Skip to content

Commit

Permalink
Merge pull request #260 from FeignClaims/fix/mulit_config_support
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Jun 17, 2024
2 parents 7394018 + fb70b92 commit 2f9199c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
8 changes: 2 additions & 6 deletions src/Hardening.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ function(
list(APPEND HARDENING_COMPILE_OPTIONS -Wstringop-overflow=4 -Wformat-overflow=2)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
target_compile_definitions(${_project_name} INTERFACE _FORTIFY_SOURCE=3)
endif()
target_compile_definitions(${_project_name} INTERFACE $<$<CONFIG:Release,RelWithDebInfo>:_FORTIFY_SOURCE=3>)
endif()

if(${ENABLE_ELF_PROTECTION})
Expand All @@ -64,9 +62,7 @@ function(
list(APPEND HARDENING_LINK_OPTIONS /guard:cf)
endif()

if(${ENABLE_STACK_PROTECTION} AND CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND HARDENING_COMPILE_OPTIONS /RTC1)
endif()
list(APPEND HARDENING_COMPILE_OPTIONS $<$<CONFIG:Debug>:/RTC1>)

if(${ENABLE_OVERFLOW_PROTECTION})
list(APPEND HARDENING_COMPILE_OPTIONS /sdl)
Expand Down
4 changes: 3 additions & 1 deletion src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ cmake_minimum_required(VERSION 3.20)

include_guard()

# fix DOWNLOAD_EXTRACT_TIMESTAMP warning in FetchContent
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
# fix DOWNLOAD_EXTRACT_TIMESTAMP warning in FetchContent
cmake_policy(SET CMP0135 NEW)
# make CheckIPOSupported prefer to honor the calling project's flags
cmake_policy(SET CMP0138 NEW)
endif()

# only useable here
Expand Down
38 changes: 19 additions & 19 deletions src/Optimization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ include_guard()

# Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build
macro(enable_interprocedural_optimization _project_name)
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
is_mingw(_is_mingw)
if(result AND NOT ${_is_mingw})
# If a static library of this project is used in another project that does not have `CMAKE_INTERPROCEDURAL_OPTIMIZATION` enabled, a linker error might happen.
# TODO set this option in `package_project` function.
message(
STATUS
"Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`"
)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(
WARNING
"Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}"
)
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
is_mingw(_is_mingw)
if(result AND NOT ${_is_mingw})
# If a static library of this project is used in another project that does not have `CMAKE_INTERPROCEDURAL_OPTIMIZATION` enabled, a linker error might happen.
# TODO set this option in `package_project` function.
message(
STATUS
"Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`"
)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
else()
message(
WARNING
"Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}"
)
endif()
endmacro()

Expand Down

0 comments on commit 2f9199c

Please sign in to comment.