Skip to content

Commit

Permalink
Separate out FP flags for build options
Browse files Browse the repository at this point in the history
  • Loading branch information
lefticus committed Dec 16, 2020
1 parent 9a874a6 commit b44b787
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<CONFIG:Debug>:/Ob0>) # Disable inlining
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/RTCsu>) # Runtime checks
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/fp:strict>) # Floating point model
target_compile_options(project_fp_options INTERFACE $<$<CONFIG:Debug>:/fp:strict>) # Floating point model
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/DMSVC_DEBUG>) # Triggers code in main.cc to catch floating point NaNs
elseif(
CMAKE_COMPILER_IS_GNUCXX
Expand Down Expand Up @@ -131,15 +131,16 @@ elseif(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
target_compile_options(project_options INTERFACE $<$<CONFIG:Release>:/Qansi-alias>) # Better optimization via strict aliasing rules
target_compile_options(project_options INTERFACE $<$<CONFIG:Release>:/Qip>) # Inter-procedural optimnization within a single file
target_compile_options(project_options INTERFACE $<$<CONFIG:Release>:/Qinline-factor:225>) # Aggressive inlining
# ADD_CXX_RELEASE_DEFINITIONS(/fp:fast=2) # Aggressive optimizations on floating-point data
# target_compile_options(project_options INTERFACE $<$<CONFIG:Release>:/fp:fast=2>) # Aggressive optimizations on floating-point data

# ADDITIONAL DEBUG-MODE-SPECIFIC FLAGS
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/fp:source>) # Use source-specified floating point precision
target_compile_options(project_fp_options INTERFACE $<$<CONFIG:Debug>:/fp:source>) # Use source-specified floating point precision

target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/Qtrapuv>) # Initialize local variables to unusual values to help detect use uninitialized
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/check:stack,uninit)# Enables runtime checking of the stack (buffer over and underruns; pointer verification>) and uninitialized variables
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/Gs0>) # Enable stack checking for all functions
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/GS>) # Buffer overrun detection
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:/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 $<$<CONFIG:Debug>:/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 $<$<CONFIG:Debug>:/traceback>) # Enables traceback on error

elseif(UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
Expand Down Expand Up @@ -177,11 +178,11 @@ elseif(UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")

# ADDITIONAL DEBUG-MODE-SPECIFIC FLAGS
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:-strict-ansi>) # Strict language conformance: Performance impact so limit to debug build
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:-fp-model source>) # Use source-specified floating point precision
target_compile_options(project_fp_options INTERFACE $<$<CONFIG:Debug>:-fp-model source>) # Use source-specified floating point precision
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:-ftrapuv>) # Initialize local variables to unusual values to help detect use uninitialized
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:-check=stack,uninit)# Enables runtime checking of the stack (buffer over and underruns; pointer verification>) and uninitialized variables
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:-fstack-security-check>) # Buffer overrun detection
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:-fp-stack-check>) # Check the floating point stack after every function call
target_compile_options(project_fp_options INTERFACE $<$<CONFIG:Debug>:-fp-stack-check>) # Check the floating point stack after every function call
target_compile_options(project_options INTERFACE $<$<CONFIG:Debug>:-traceback>) # Enables traceback on error

endif() # COMPILER TYPE
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
18 changes: 9 additions & 9 deletions src/EnergyPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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})
Expand Down Expand Up @@ -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
Expand All @@ -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/)
Expand All @@ -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}")
Expand All @@ -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}")
Expand Down
13 changes: 10 additions & 3 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions third_party/SQLite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<CONFIG:Debug>:/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)
Expand Down
2 changes: 1 addition & 1 deletion third_party/SQLite/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down

5 comments on commit b44b787

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake_modernize (lefticus) - Win64-Windows-10-VisualStudio-16: Build Failed

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake_modernize (lefticus) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: Build Failed

Build Badge Test Badge Coverage Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake_modernize (lefticus) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: Build Failed

Build Badge Test Badge Coverage Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake_modernize (lefticus) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: Build Failed

Build Badge Test Badge

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake_modernize (lefticus) - x86_64-MacOS-10.15-clang-11.0.0: Build Failed

Build Badge Test Badge

Please sign in to comment.