Skip to content

Commit 4552fca

Browse files
committed
Use compile options instead of interfaces
1 parent e86055e commit 4552fca

File tree

4 files changed

+22
-53
lines changed

4 files changed

+22
-53
lines changed

cmake/Config.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake")

cmake/LTO.cmake

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
# Link Time Optimization (LTO)
2-
add_library(lto INTERFACE)
3-
4-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
5-
target_compile_options(lto INTERFACE -flto)
6-
target_link_options(lto INTERFACE -flto)
7-
else()
8-
message(WARNING "LTO not configured for compiler: ${CMAKE_CXX_COMPILER_ID}")
9-
endif()
10-
11-
# Function to apply lto
121
function(enable_lto target)
132
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
14-
target_link_libraries(${target} PRIVATE lto)
15-
message(STATUS "✅ Enabled LTO for target: ${target}")
3+
set_property(TARGET ${target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
4+
message(STATUS "🔧\tEnabled LTO for target ${target}")
165
endif()
176
endfunction()

cmake/Sanitizers.cmake

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
# Enable AddressSanitizer + UndefinedBehaviorSanitizer only for "Sanitize" build type
21
if(CMAKE_BUILD_TYPE STREQUAL "Sanitize")
32
set(SANITIZER_FLAGS
43
-fsanitize=address
54
-fsanitize=undefined
65
-O1
76
-g
87
)
9-
10-
add_library(sanitizers INTERFACE)
11-
target_compile_options(sanitizers INTERFACE ${SANITIZER_FLAGS})
12-
target_link_options(sanitizers INTERFACE ${SANITIZER_FLAGS})
13-
message(STATUS "✅ Sanitize build enabled with flags: ${SANITIZER_FLAGS}")
8+
message(STATUS "✅\tSanitize build enabled with flags: ${SANITIZER_FLAGS}")
149
endif()
1510

1611
function(enable_sanitizers target)
17-
if(TARGET sanitizers)
18-
target_link_libraries(${target} PRIVATE sanitizers)
19-
message(STATUS "✅ Enabled sanitizers for target ${target}")
12+
if(CMAKE_BUILD_TYPE STREQUAL "Sanitize")
13+
target_compile_options(${target} PRIVATE ${SANITIZER_FLAGS})
14+
message(STATUS "✅\tEnabled sanitizers for target ${target}")
2015
endif()
2116
endfunction()

cmake/Warnings.cmake

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
1-
# Standard warnings
2-
add_library(warnings INTERFACE)
3-
4-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
5-
target_compile_options(warnings INTERFACE
6-
-Wall
7-
-Wextra
8-
-Wpedantic
9-
-Wconversion
10-
-Wsign-conversion
11-
)
12-
else()
13-
message(WARNING "Warnings not configured for compiler: ${CMAKE_CXX_COMPILER_ID}")
14-
endif()
15-
16-
# Warnings as errors
17-
add_library(strict_warnings INTERFACE)
18-
19-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
20-
target_compile_options(strict_warnings INTERFACE -Werror)
21-
target_link_libraries(strict_warnings INTERFACE warnings)
22-
else()
23-
message(WARNING "Strict warnings not configured for compiler: ${CMAKE_CXX_COMPILER_ID}")
24-
endif()
25-
26-
# Function to apply warnings
271
function(enable_warnings target)
28-
target_link_libraries(${target} PRIVATE warnings)
29-
message(STATUS "⚠️ Enabled warnings for target ${target}")
2+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
3+
target_compile_options(${target} PRIVATE
4+
-Wall
5+
-Wextra
6+
-Wpedantic
7+
-Wconversion
8+
-Wsign-conversion
9+
)
10+
message(STATUS "⚠️\tEnabled warnings for target ${target}")
11+
endif()
3012
endfunction()
3113

32-
# Function to apply warnings as errors (aka strict warnings)
3314
function(enable_strict_warnings target)
34-
target_link_libraries(${target} PRIVATE strict_warnings)
35-
message(STATUS "⚠️ Enabled warnings as errors for target ${target}")
15+
enable_warnings(${target})
16+
target_compile_options(${target} PRIVATE -Werror)
17+
message(STATUS "🚨\tWarnings treated as errors for target ${target}")
3618
endfunction()

0 commit comments

Comments
 (0)