From b44b78762de6a57c5be31f9e0700f4af01426ba3 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 15 Dec 2020 22:52:17 -0700 Subject: [PATCH] Separate out FP flags for build options --- CMakeLists.txt | 2 ++ cmake/CompilerFlags.cmake | 13 +++++++------ .../CMakeLists.txt | 2 +- src/EnergyPlus/CMakeLists.txt | 18 +++++++++--------- third_party/CMakeLists.txt | 13 ++++++++++--- third_party/SQLite/CMakeLists.txt | 8 ++------ third_party/SQLite/sqlite3.c | 2 +- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a75a8ec128..1c78a07a832 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) add_library(project_options INTERFACE) target_compile_features(project_options INTERFACE cxx_std_17) +add_library(project_fp_options INTERFACE) + add_library(project_warnings INTERFACE) set(THREADS_PREFER_PTHREAD_FLAG ON) diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index aeeec8d3c7b..2c6ec74ffe0 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -57,7 +57,7 @@ if(MSVC AND NOT ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")) # Visual C++ (VS # ADDITIONAL DEBUG-MODE-SPECIFIC FLAGS target_compile_options(project_options INTERFACE $<$:/Ob0>) # Disable inlining target_compile_options(project_options INTERFACE $<$:/RTCsu>) # Runtime checks - target_compile_options(project_options INTERFACE $<$:/fp:strict>) # Floating point model + target_compile_options(project_fp_options INTERFACE $<$:/fp:strict>) # Floating point model target_compile_options(project_options INTERFACE $<$:/DMSVC_DEBUG>) # Triggers code in main.cc to catch floating point NaNs elseif( CMAKE_COMPILER_IS_GNUCXX @@ -131,15 +131,16 @@ elseif(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") target_compile_options(project_options INTERFACE $<$:/Qansi-alias>) # Better optimization via strict aliasing rules target_compile_options(project_options INTERFACE $<$:/Qip>) # Inter-procedural optimnization within a single file target_compile_options(project_options INTERFACE $<$:/Qinline-factor:225>) # Aggressive inlining - # ADD_CXX_RELEASE_DEFINITIONS(/fp:fast=2) # Aggressive optimizations on floating-point data + # target_compile_options(project_options INTERFACE $<$:/fp:fast=2>) # Aggressive optimizations on floating-point data # ADDITIONAL DEBUG-MODE-SPECIFIC FLAGS - target_compile_options(project_options INTERFACE $<$:/fp:source>) # Use source-specified floating point precision + target_compile_options(project_fp_options INTERFACE $<$:/fp:source>) # Use source-specified floating point precision + target_compile_options(project_options INTERFACE $<$:/Qtrapuv>) # Initialize local variables to unusual values to help detect use uninitialized target_compile_options(project_options INTERFACE $<$:/check:stack,uninit)# Enables runtime checking of the stack (buffer over and underruns; pointer verification>) and uninitialized variables target_compile_options(project_options INTERFACE $<$:/Gs0>) # Enable stack checking for all functions target_compile_options(project_options INTERFACE $<$:/GS>) # Buffer overrun detection - target_compile_options(project_options INTERFACE $<$:/Qfp-stack-check>)# Tells the compiler to generate extra code after every function call to ensure fp stack is as expected + target_compile_options(project_fp_options INTERFACE $<$:/Qfp-stack-check>)# Tells the compiler to generate extra code after every function call to ensure fp stack is as expected target_compile_options(project_options INTERFACE $<$:/traceback>) # Enables traceback on error elseif(UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") @@ -177,11 +178,11 @@ elseif(UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") # ADDITIONAL DEBUG-MODE-SPECIFIC FLAGS target_compile_options(project_options INTERFACE $<$:-strict-ansi>) # Strict language conformance: Performance impact so limit to debug build - target_compile_options(project_options INTERFACE $<$:-fp-model source>) # Use source-specified floating point precision + target_compile_options(project_fp_options INTERFACE $<$:-fp-model source>) # Use source-specified floating point precision target_compile_options(project_options INTERFACE $<$:-ftrapuv>) # Initialize local variables to unusual values to help detect use uninitialized target_compile_options(project_options INTERFACE $<$:-check=stack,uninit)# Enables runtime checking of the stack (buffer over and underruns; pointer verification>) and uninitialized variables target_compile_options(project_options INTERFACE $<$:-fstack-security-check>) # Buffer overrun detection - target_compile_options(project_options INTERFACE $<$:-fp-stack-check>) # Check the floating point stack after every function call + target_compile_options(project_fp_options INTERFACE $<$:-fp-stack-check>) # Check the floating point stack after every function call target_compile_options(project_options INTERFACE $<$:-traceback>) # Enables traceback on error endif() # COMPILER TYPE diff --git a/scripts/dev/generate_embeddable_epJSON_schema/CMakeLists.txt b/scripts/dev/generate_embeddable_epJSON_schema/CMakeLists.txt index d20ed66159e..e2eff6770c0 100644 --- a/scripts/dev/generate_embeddable_epJSON_schema/CMakeLists.txt +++ b/scripts/dev/generate_embeddable_epJSON_schema/CMakeLists.txt @@ -1,5 +1,5 @@ set(generate_embeddedable_epJSON_schema_src generate_embeddable_epJSON_schema.cpp) add_executable(generate_embeddedable_epJSON_schema ${generate_embeddedable_epJSON_schema_src}) -target_link_libraries(generate_embeddedable_epJSON_schema PRIVATE project_options project_warnings) +target_link_libraries(generate_embeddedable_epJSON_schema PRIVATE project_options project_fp_options project_warnings) set_target_properties(generate_embeddedable_epJSON_schema PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/scripts") diff --git a/src/EnergyPlus/CMakeLists.txt b/src/EnergyPlus/CMakeLists.txt index fb6d3d2312d..64a661235d3 100644 --- a/src/EnergyPlus/CMakeLists.txt +++ b/src/EnergyPlus/CMakeLists.txt @@ -791,7 +791,7 @@ endif() add_library(energyplusparser STATIC ${INPUTPARSING_SRC}) add_dependencies(energyplusparser GenerateEmbeddedEpJSONSchema) target_link_libraries(energyplusparser PUBLIC re2 fmt::fmt ${CMAKE_DL_LIBS}) -target_link_libraries(energyplusparser PRIVATE project_options project_warnings) +target_link_libraries(energyplusparser PRIVATE project_options project_fp_options project_warnings) if(WIN32) target_link_libraries(energyplusparser PUBLIC Shlwapi) endif() @@ -815,7 +815,7 @@ target_link_libraries( Windows-CalcEngine airflownetworklib) -target_link_libraries(energypluslib PRIVATE project_options project_warnings) +target_link_libraries(energypluslib PRIVATE project_options project_fp_options project_warnings) if(OPENGL_FOUND) target_link_libraries(energypluslib PUBLIC penumbra) @@ -879,7 +879,7 @@ else() # windows ${API_CORE_SRC} "${CMAKE_CURRENT_BINARY_DIR}/energyplusapi.rc") endif() target_link_libraries(energyplusapi PUBLIC energypluslib) -target_link_libraries(energyplusapi PRIVATE project_options project_warnings) +target_link_libraries(energyplusapi PRIVATE project_options project_fp_options project_warnings) set_target_properties(energyplusapi PROPERTIES INSTALL_NAME_DIR "@executable_path") @@ -895,7 +895,7 @@ if(APPLE OR UNIX) else() # windows add_executable(energyplus main.cc "${CMAKE_CURRENT_BINARY_DIR}/energyplus.rc") endif() -target_link_libraries(energyplus PRIVATE energyplusapi project_options project_warnings) +target_link_libraries(energyplus PRIVATE energyplusapi project_options project_fp_options project_warnings) set_target_properties(energyplus PROPERTIES VERSION ${ENERGYPLUS_VERSION}) set_target_properties(energyplusapi PROPERTIES VERSION ${ENERGYPLUS_VERSION}) @@ -988,7 +988,7 @@ if(BUILD_TESTING) # Build the test executable add_executable(TestEnergyPlusCallbacks test_ep_as_library.cc) target_link_libraries(TestEnergyPlusCallbacks PRIVATE energyplusapi - project_options project_warnings) + project_options project_fp_options project_warnings) add_test( NAME "API.LegacyCallbackTest" COMMAND @@ -1005,7 +1005,7 @@ if(BUILD_TESTING) add_executable(TestAPI_Functional_C ${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestFunctional.c) target_link_libraries(TestAPI_Functional_C PRIVATE energyplusapi - project_options project_warnings) + project_options project_fp_options project_warnings) add_test(NAME "API.TestFunctionalC" COMMAND TestAPI_Functional_C) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tst/api/) @@ -1014,8 +1014,8 @@ if(BUILD_TESTING) file(MAKE_DIRECTORY ${TEST_DIR}) add_executable(TestAPI_Runtime_C ${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestRuntime.c) - target_link_libraries(TestAPI_Runtime_C PRIVATE energyplusapi project_options ) - target_compile_options(TestAPI_Runtime_C PRIVATE -Wall -Wextra -Wno-unused) + target_link_libraries(TestAPI_Runtime_C PRIVATE energyplusapi project_options project_fp_options) + #target_compile_options(TestAPI_Runtime_C PRIVATE -Wall -Wextra -Wno-unused) add_test(NAME "API.TestRuntimeC" COMMAND TestAPI_Runtime_C -d "${TEST_DIR}" -w "${EPW_FILE}" -D "${IDF_FILE}") @@ -1025,7 +1025,7 @@ if(BUILD_TESTING) add_executable(TestAPI_DataTransfer_C ${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestDataTransfer.c) target_link_libraries(TestAPI_DataTransfer_C PRIVATE energyplusapi - project_options project_warnings) + project_options project_fp_options project_warnings) add_test(NAME "API.TestDataTransferC" COMMAND TestAPI_DataTransfer_C -d "${TEST_DIR}" -w "${EPW_FILE}" -D "${IDF_FILE}") diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 6f3e5340ed6..24fdc6a5e88 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -6,7 +6,6 @@ # To avoid modifying every third_party library # we link the project_options in here for every library in this # subdirectory -link_libraries(project_options) if (NOT MSVC) add_compile_options(-Wno-pedantic -Wno-unused-parameter) @@ -24,6 +23,15 @@ if(OPENGL_FOUND) CACHE BOOL "" FORCE) endif() +# We don't want to enable the global warnings for any of the third party projects +link_libraries(project_options) +add_subdirectory(SQLite) +set_target_properties(sqlite PROPERTIES FOLDER ThirdParty/SQLite) + +# Then add in the FP options after SQLite project +# because it cannot compile with any of the checked FP options +link_libraries(project_fp_options) + if(BUILD_TESTING) set(gtest_force_shared_crt ON @@ -43,8 +51,7 @@ if(BUILD_TESTING) set_target_properties(gmock_main PROPERTIES FOLDER ThirdParty/gtest) endif() -add_subdirectory(SQLite) -set_target_properties(sqlite PROPERTIES FOLDER ThirdParty/SQLite) + add_subdirectory(ObjexxFCL) set_target_properties(objexx PROPERTIES FOLDER ThirdParty/ObjexxFCL) add_subdirectory(BCVTB) diff --git a/third_party/SQLite/CMakeLists.txt b/third_party/SQLite/CMakeLists.txt index e61c0f57bba..9f0910dd039 100644 --- a/third_party/SQLite/CMakeLists.txt +++ b/third_party/SQLite/CMakeLists.txt @@ -3,12 +3,8 @@ set(SRC sqlite3.h sqlite3.c) add_library(sqlite ${SRC}) if(MSVC) # visual c++ (VS 2013) - target_compile_options(sqlite PRIVATE -W0) - target_compile_options( - sqlite PRIVATE $<$:/fp:fast>) # override fp:strict in debug - # builds -elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" -)# g++/Clang + target_compile_options(sqlite PRIVATE -W0) +elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")# g++/Clang target_compile_options(sqlite PRIVATE -w) elseif(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") target_compile_options(sqlite PRIVATE /W0) diff --git a/third_party/SQLite/sqlite3.c b/third_party/SQLite/sqlite3.c index 61bfdeb766b..622cf460fef 100644 --- a/third_party/SQLite/sqlite3.c +++ b/third_party/SQLite/sqlite3.c @@ -21604,7 +21604,7 @@ static sqlite3_int64 localtimeOffset( static const struct { u8 eType; /* Transformation type code */ u8 nName; /* Length of th name */ - char *zName; /* Name of the transformation */ + const char *zName; /* Name of the transformation */ double rLimit; /* Maximum NNN value for this transform */ double rXform; /* Constant used for this transform */ } aXformType[] = {