Skip to content

Commit 2f9199c

Browse files
authored
Merge pull request #260 from FeignClaims/fix/mulit_config_support
2 parents 7394018 + fb70b92 commit 2f9199c

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

src/Hardening.cmake

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ function(
4444
list(APPEND HARDENING_COMPILE_OPTIONS -Wstringop-overflow=4 -Wformat-overflow=2)
4545
endif()
4646

47-
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
48-
target_compile_definitions(${_project_name} INTERFACE _FORTIFY_SOURCE=3)
49-
endif()
47+
target_compile_definitions(${_project_name} INTERFACE $<$<CONFIG:Release,RelWithDebInfo>:_FORTIFY_SOURCE=3>)
5048
endif()
5149

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

67-
if(${ENABLE_STACK_PROTECTION} AND CMAKE_BUILD_TYPE STREQUAL "Debug")
68-
list(APPEND HARDENING_COMPILE_OPTIONS /RTC1)
69-
endif()
65+
list(APPEND HARDENING_COMPILE_OPTIONS $<$<CONFIG:Debug>:/RTC1>)
7066

7167
if(${ENABLE_OVERFLOW_PROTECTION})
7268
list(APPEND HARDENING_COMPILE_OPTIONS /sdl)

src/Index.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ cmake_minimum_required(VERSION 3.20)
44

55
include_guard()
66

7-
# fix DOWNLOAD_EXTRACT_TIMESTAMP warning in FetchContent
87
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
8+
# fix DOWNLOAD_EXTRACT_TIMESTAMP warning in FetchContent
99
cmake_policy(SET CMP0135 NEW)
10+
# make CheckIPOSupported prefer to honor the calling project's flags
11+
cmake_policy(SET CMP0138 NEW)
1012
endif()
1113

1214
# only useable here

src/Optimization.cmake

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ include_guard()
22

33
# Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build
44
macro(enable_interprocedural_optimization _project_name)
5-
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
6-
include(CheckIPOSupported)
7-
check_ipo_supported(RESULT result OUTPUT output)
8-
is_mingw(_is_mingw)
9-
if(result AND NOT ${_is_mingw})
10-
# 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.
11-
# TODO set this option in `package_project` function.
12-
message(
13-
STATUS
14-
"Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`"
15-
)
16-
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
17-
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
18-
else()
19-
message(
20-
WARNING
21-
"Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}"
22-
)
23-
endif()
5+
include(CheckIPOSupported)
6+
check_ipo_supported(RESULT result OUTPUT output)
7+
is_mingw(_is_mingw)
8+
if(result AND NOT ${_is_mingw})
9+
# 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.
10+
# TODO set this option in `package_project` function.
11+
message(
12+
STATUS
13+
"Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`"
14+
)
15+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
16+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
17+
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
18+
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
19+
else()
20+
message(
21+
WARNING
22+
"Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}"
23+
)
2424
endif()
2525
endmacro()
2626

0 commit comments

Comments
 (0)