Skip to content

Commit

Permalink
Disable IPO by default on debug builds in CMake (#219)
Browse files Browse the repository at this point in the history
Debug builds produce slow binaries. We do not gain anything by using IPO
here. On the contrary, IPO increases build times considerably. So we
disable IPO by default on debug builds to save some developer time.


---------

Co-authored-by: r.jaepel <[email protected]>
  • Loading branch information
sleweke-bayer and ronald-jaepel authored Jul 10, 2024
1 parent 0194ecb commit bc36a1a
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Other configuration options
# ---------------------------------------------------

# Option that allows users to build release or debug version
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE} (default)")
endif()

# Default IPO setting: OFF for Debug, ON for all other build types
set(DEFAULT_IPO_ENABLED ON)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEFAULT_IPO_ENABLED OFF)
endif()

include(FeatureSummary)

option(ENABLE_LOGGING "Enables logging" ON)
Expand Down Expand Up @@ -130,7 +142,7 @@ add_feature_info(ENABLE_TESTS ENABLE_TESTS "Build CADET tests")
option(ENABLE_PACKAGED_SUNDIALS "Use packaged SUNDIALS code" ON)
add_feature_info(ENABLE_PACKAGED_SUNDIALS ENABLE_PACKAGED_SUNDIALS "Use packaged SUNDIALS code")

option(ENABLE_IPO "Enable interprocedural optimization if compiler supports it" ON)
option(ENABLE_IPO "Enable interprocedural optimization if compiler supports it" ${DEFAULT_IPO_ENABLED})
add_feature_info(ENABLE_IPO ENABLE_IPO "Enable interprocedural optimization if compiler supports it")

option(ENABLE_STATIC_LINK_DEPS "Prefer static over dynamic linking of dependencies" OFF)
Expand All @@ -157,12 +169,6 @@ if (UNIX)
endif()
endif()

# Option that allows users to build release or debug version
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE} (default)")
endif()

# ---------------------------------------------------
# Check build environment
# ---------------------------------------------------
Expand Down Expand Up @@ -453,11 +459,20 @@ if (ENABLE_PLATFORM_TIMER)
endif()
endif()

target_compile_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -pedantic-errors -Wextra -Wno-unused-parameter -Wno-unused-function> #-Wconversion -Wsign-conversion
$<$<CXX_COMPILER_ID:MSVC>:
/W4 /wd4100 /bigobj>
)
else()
target_compile_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -pedantic-errors -Wextra -Wno-unused-parameter -Wno-unused-function> #-Wconversion -Wsign-conversion
$<$<CXX_COMPILER_ID:MSVC>:
/W4 /wd4100>
)
endif()


add_library(CADET::AD INTERFACE IMPORTED)
if (ADLIB STREQUAL "sfad")
Expand Down

0 comments on commit bc36a1a

Please sign in to comment.