Skip to content

Commit c4d166a

Browse files
authored
Merge pull request cpp-best-practices#2 from Lectem/master
Use target_compile_options and interface library
2 parents f2eb974 + 4723b6e commit c4d166a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
cmake_minimum_required(VERSION 3.2)
22

3+
# Link this 'library' to use the following warnings
4+
add_library(project_warnings INTERFACE)
5+
36
if (CMAKE_COMPILER_IS_GNUCC)
47
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE)
58

@@ -9,18 +12,22 @@ if (CMAKE_COMPILER_IS_GNUCC)
912
endif()
1013

1114
if (MSVC)
12-
add_compile_options(/W4)
15+
target_compile_options(project_warnings INTERFACE /W4)
1316
else()
14-
add_compile_options(-Wall -Wextra -Wpedantic)
17+
target_compile_options(project_warnings INTERFACE -Wall -Wextra -Wpedantic)
1518
endif()
1619

1720
add_executable(intro main.cpp)
1821
target_compile_features(intro PRIVATE cxx_lambda_init_captures)
22+
target_link_libraries(intro PRIVATE project_warnings)
23+
1924
target_link_libraries(intro --coverage)
2025

2126
enable_testing()
2227

2328
add_executable(tester tester.cpp)
29+
target_link_libraries(tester PRIVATE project_warnings)
30+
2431
target_link_libraries(tester --coverage)
2532
add_test(Tester tester)
2633

0 commit comments

Comments
 (0)