Skip to content

Commit

Permalink
Merge pull request #48 from bigladder/pragma-warning-solution
Browse files Browse the repository at this point in the history
Resolve all warnings using pragmas for third-party header-only libraries.
  • Loading branch information
nealkruis authored Mar 17, 2022
2 parents 09511bc + 571286b commit 1c699e7
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 116 deletions.
11 changes: 11 additions & 0 deletions src/kiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ target_link_libraries(kiva libkiva groundplot boost_program_options yaml-cpp)

target_include_directories(kiva PRIVATE "${groundplot_SOURCE_DIR}")

set(kiva_suppress_warnings Main.cpp
Input.cpp
InputParser.cpp
Simulator.cpp)

target_compile_options(kiva PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wpedantic -Werror>
)

if (KIVA_COVERAGE)
add_coverage(kiva)
endif()
Expand Down
16 changes: 8 additions & 8 deletions src/kiva/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Simulator::initializeConditions() {

for (boost::posix_time::ptime t = tAccelStart; t <= tAccelEnd; t += accelTimestep) {
updateBoundaryConditions(t);
ground.calculate(bcs, accelTimestep.total_seconds());
ground.calculate(bcs, static_cast<double>(accelTimestep.total_seconds()));
printStatus(t);
}

Expand All @@ -130,7 +130,7 @@ void Simulator::initializeConditions() {

for (boost::posix_time::ptime t = tWarmupStart; t <= tWarmupEnd; t += simulationTimestep) {
updateBoundaryConditions(t);
ground.calculate(bcs, simulationTimestep.total_seconds());
ground.calculate(bcs, static_cast<double>(accelTimestep.total_seconds()));
printStatus(t);
}
}
Expand Down Expand Up @@ -224,9 +224,9 @@ void Simulator::initializePlots() {
boost::posix_time::ptime endTime(input.output.outputSnapshots[p].endDate +
boost::gregorian::days(1));

plots[p].tStart = (startTime - input.simulationControl.startTime).total_seconds();
plots[p].nextPlotTime = (startTime - input.simulationControl.startTime).total_seconds();
plots[p].tEnd = (endTime - input.simulationControl.startTime).total_seconds();
plots[p].tStart = static_cast<double>((startTime - input.simulationControl.startTime).total_seconds());
plots[p].nextPlotTime = static_cast<double>((startTime - input.simulationControl.startTime).total_seconds());
plots[p].tEnd = static_cast<double>((endTime - input.simulationControl.startTime).total_seconds());
}
}

Expand All @@ -238,7 +238,7 @@ void Simulator::simulate() {
boost::posix_time::time_duration simDuration = simEnd - simStart;

prevOutputTime = input.simulationControl.startTime - input.output.outputReport.minFrequency;
double timestep = input.simulationControl.timestep.total_seconds();
double timestep = static_cast<double>(input.simulationControl.timestep.total_seconds());

for (boost::posix_time::ptime t = simStart; t < simEnd;
t = t + input.simulationControl.timestep) {
Expand All @@ -264,7 +264,7 @@ void Simulator::simulate() {

void Simulator::plot(boost::posix_time::ptime t) {
for (std::size_t p = 0; p < plots.size(); p++) {
if (plots[p].makeNewFrame((t - input.simulationControl.startTime).total_seconds())) {
if (plots[p].makeNewFrame(static_cast<double>((t - input.simulationControl.startTime).total_seconds()))) {
std::string timeStamp = to_simple_string(t);

std::size_t nI = plots[p].iMax - plots[p].iMin + 1;
Expand Down Expand Up @@ -370,7 +370,7 @@ double Simulator::getInitialTemperature(boost::posix_time::ptime t, double z) {
boost::gregorian::date dayBegin(year, boost::gregorian::Jan, 1);
boost::posix_time::ptime tYearStart(dayBegin);
boost::posix_time::time_duration tSinceYearStart = t - tYearStart;
double trel = tSinceYearStart.total_seconds();
double trel = static_cast<double>(tSinceYearStart.total_seconds());
double tshift = weatherData.hourOfMinimumTemperature * 60.0 * 60.0;
double seconds_in_day = 60.0 * 60.0 * 24.0;
double Tamp = (weatherData.maximumAverageMontlyTemperature -
Expand Down
12 changes: 9 additions & 3 deletions src/libgroundplot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
project(groundplot)

set(kiva_src GroundPlot.cpp
GroundPlot.hpp )
set(groundplot_src GroundPlot.cpp
GroundPlot.hpp )

add_library(groundplot STATIC ${kiva_src})
add_library(groundplot STATIC ${groundplot_src})

target_link_libraries(groundplot fmt mgl-static libkiva)

target_include_directories(groundplot PUBLIC "${MathGL2_SOURCE_DIR}/include" "${MathGL2_BINARY_DIR}/include")

target_compile_options(groundplot PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wpedantic -Werror>
)

if (KIVA_COVERAGE)
add_coverage(groundplot)
endif()
11 changes: 6 additions & 5 deletions src/libgroundplot/GroundPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,22 @@ GroundPlot::GroundPlot(SnapshotSettings &snapshotSettings, Domain &domain, Found
}

if (sliceType == Z_1D) {
mglData hDatRef(vAxis.nN), hGridRef(vAxis.nN + 1), TDatRef(vAxis.nN), TGridRef(vAxis.nN + 1);
mglData hDatRef(static_cast<long>(vAxis.nN)), hGridRef(static_cast<long>(vAxis.nN + 1)), TDatRef(static_cast<long>(vAxis.nN)), TGridRef(static_cast<long>(vAxis.nN + 1));
TDat = TDatRef;
TGrid = TGridRef;
hDat = hDatRef;
hGrid = hGridRef;
} else {
mglData hDatRef(hAxis.nN), hGridRef(hAxis.nN + 1), TDatRef(hAxis.nN, vAxis.nN),
TGridRef(hAxis.nN + 1, vAxis.nN + 1);
mglData hDatRef(static_cast<long>(hAxis.nN)), hGridRef(static_cast<long>(hAxis.nN + 1)), TDatRef(static_cast<long>(hAxis.nN), static_cast<long>(vAxis.nN)),
TGridRef(static_cast<long>(hAxis.nN + 1), static_cast<long>(vAxis.nN + 1));
TDat = TDatRef;
TGrid = TGridRef;
hDat = hDatRef;
hGrid = hGridRef;
}

mglData vDatRef(vAxis.nN), vGridRef(vAxis.nN + 1), cDatRef(contourLevels);
mglData vDatRef(static_cast<long>(vAxis.nN)), vGridRef(static_cast<long>(vAxis.nN + 1)),
cDatRef(static_cast<long>(contourLevels));

vDat = vDatRef;
vGrid = vGridRef;
Expand Down Expand Up @@ -250,7 +251,7 @@ void GroundPlot::createFrame(std::string timeStamp) {
gr.Clf(1, 1, 1);
double aspect = 1.0;
int height = snapshotSettings.size;
int width = height * aspect;
int width = height * static_cast<int>(aspect);

gr.SetSize(width, height);

Expand Down
13 changes: 13 additions & 0 deletions src/libgroundplot/GroundPlot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
#ifndef GROUNDPLOT_H_
#define GROUNDPLOT_H_

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4068) // Unknown pragma
#pragma warning(disable : 4458) // Declaration hides class member
#elif defined(__gnu_linux__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#endif
#include <mgl2/mgl.h>
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__gnu_linux__)
#pragma GCC diagnostic pop
#endif

#include "../libkiva/Domain.hpp"
#include "../libkiva/Foundation.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/libkiva/Aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void Aggregator::calc_weighted_results() {
validate();
}
results.reset();
double Tz, Tr;
double Tz{293.15}, Tr{293.15};
for (auto &instance : instances) {
Ground *grnd = instance.first;
Tz = surface_type == Surface::ST_WALL_INT ? grnd->bcs.wallConvectiveTemp
Expand Down
16 changes: 8 additions & 8 deletions src/libkiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ configure_file (
"${PROJECT_BINARY_DIR}/Version.hpp"
)

set(kiva_src Aggregator.cpp
set(libkiva_src Aggregator.cpp
Aggregator.hpp
Algorithms.cpp
Algorithms.hpp
Expand Down Expand Up @@ -155,20 +155,15 @@ set(kiva_src Aggregator.cpp

option( KIVA_STATIC_LIB "Make libkiva a static library" ON )

if (MSVC)
# Remove "potential loss of data" warning in Boost
set_source_files_properties(Geometry.cpp PROPERTIES COMPILE_FLAGS /wd4244)
endif()

if (KIVA_STATIC_LIB)
add_library(libkiva STATIC ${kiva_src})
add_library(libkiva STATIC ${libkiva_src})
target_compile_definitions(libkiva PRIVATE LIBKIVA_STATIC_DEFINE)
if(UNIX)
target_compile_options(libkiva PUBLIC -fPIC)
endif()
else()
set(CMAKE_MACOSX_RPATH 1)
add_library(libkiva SHARED ${kiva_src})
add_library(libkiva SHARED ${libkiva_src})
if(KIVA_EXE_BUILD)
install(TARGETS libkiva DESTINATION bin/)
endif()
Expand All @@ -184,6 +179,11 @@ target_include_directories(libkiva PUBLIC
"${BOOST_SOURCE_DIR}"
"${kiva_SOURCE_DIR}/vendor/eigen")

target_compile_options(libkiva PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wpedantic -Werror>
)
target_compile_features(libkiva PUBLIC cxx_std_17) # Should be PRIVATE once boost is cleaned out of public API

include(GenerateExportHeader)
Expand Down
Loading

0 comments on commit 1c699e7

Please sign in to comment.