Skip to content

Commit

Permalink
cmake: using CMAKE_BUILD_TYPE instead of custom vars. (#102)
Browse files Browse the repository at this point in the history
for optimized build, checking first proper lto support which
cmake will apply proper flag whether it is clang or gcc.
  • Loading branch information
devnexen authored Apr 27, 2024
1 parent c942f82 commit 2247f5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 2 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ ExternalProject_Add(heap_layers
)

#Create configure options
option(DEBUG "Build with debugging symbols" OFF) #replace with CMAKE_BUILD_TYPE?
option(OPTIMIZE " Build with optimizations" ON) #replace with CMAKE_BUILD_TYPE?
option(GCOV "Build with gcov profiling support" OFF)
option(CLANGCOV "Build with clangcov profiling support" OFF)
set(RANDOMIZATION "1" CACHE STRING "0: no randomization. 1: freelist init only. 2: freelist init + free fastpath")
Expand Down Expand Up @@ -91,14 +89,8 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
set(ICC TRUE)
endif()

if (${DEBUG})
add_definitions(-g)
endif()

if(${OPTIMIZE})
add_definitions(-O3 -flto -D_FORTIFY_SOURCE=2)
else()
add_definitions(-O0)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

if (${GCOV} AND GCC)
Expand Down
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ set(mesh_src
#Add a target for the mesh shared library
add_library(mesh SHARED ${mesh_src})
target_link_libraries(mesh PRIVATE -pthread -ldl)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT HAS_IPO)
if(${HAS_IPO})
set_property(TARGET mesh PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
target_compile_definitions(mesh PRIVATE -D_FORTIFY_SOURCE=2)
endif()

#Create a set of source files for the unit tests
set(unit_src
Expand Down

0 comments on commit 2247f5b

Please sign in to comment.