|
1 | | -function(setup_compiler TARGET) |
2 | | -set_target_properties(${TARGET} |
3 | | - PROPERTIES |
| 1 | +function(setup_compiler project_name) |
| 2 | + set_target_properties(${project_name} |
| 3 | + PROPERTIES |
4 | 4 | EXPORT_COMPILE_COMMANDS ON |
5 | 5 | CXX_STANDARD_REQUIRED YES |
6 | 6 | CXX_EXTENSIONS NO |
7 | 7 | CXX_STANDARD 17 |
8 | | -) |
| 8 | + ) |
9 | 9 |
|
10 | | -target_compile_features(${TARGET} |
11 | | - PRIVATE |
| 10 | + target_compile_features(${project_name} |
| 11 | + PRIVATE |
12 | 12 | cxx_std_17 |
13 | | -) |
| 13 | + ) |
14 | 14 |
|
15 | | -set(NOT_MSVC_COMPILE_OPTIONS |
16 | | - "-Wall" |
17 | | - "-Wextra" |
18 | | - "-Wpedantic" |
19 | | - "-Wno-error=unused" |
20 | | - "-Wno-error=unused-function" |
21 | | - "-Wno-error=unused-parameter" |
22 | | - "-Wno-error=unused-value" |
23 | | - "-Wno-error=unused-variable" |
24 | | - "-Wno-error=unused-local-typedefs" |
25 | | - "-Wno-error=unused-but-set-parameter" |
26 | | - "-Wno-error=unused-but-set-variable" |
27 | | - "-fno-rtti" |
28 | | -) |
| 15 | + set(NOT_MSVC_COMPILE_OPTIONS |
| 16 | + "-Wall" |
| 17 | + "-Wextra" |
| 18 | + "-Wpedantic" |
| 19 | + "-Wno-error=unused" |
| 20 | + "-Wno-error=unused-function" |
| 21 | + "-Wno-error=unused-parameter" |
| 22 | + "-Wno-error=unused-value" |
| 23 | + "-Wno-error=unused-variable" |
| 24 | + "-Wno-error=unused-local-typedefs" |
| 25 | + "-Wno-error=unused-but-set-parameter" |
| 26 | + "-Wno-error=unused-but-set-variable" |
| 27 | + "-fno-rtti" |
| 28 | + ) |
29 | 29 |
|
30 | | -set(NOT_MSVC_LINK_OPTIONS) |
| 30 | + set(NOT_MSVC_LINK_OPTIONS) |
31 | 31 |
|
32 | | -set(MSVC_COMPILE_OPTIONS |
33 | | - "/W4" |
34 | | -) |
| 32 | + set(MSVC_COMPILE_OPTIONS |
| 33 | + "/W4" |
| 34 | + ) |
35 | 35 |
|
36 | | -set(MSVC_LINK_OPTIONS) |
| 36 | + set(MSVC_LINK_OPTIONS) |
37 | 37 |
|
38 | | -if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
39 | | - list(APPEND NOT_MSVC_COMPILE_OPTIONS |
40 | | - "-Werror" |
41 | | - "-g" |
42 | | - "-fsanitize=address,undefined" |
43 | | - "-fno-omit-frame-pointer" |
44 | | - ) |
| 38 | + if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 39 | + list(APPEND NOT_MSVC_COMPILE_OPTIONS |
| 40 | + "-Werror" |
| 41 | + "-g" |
| 42 | + "-fsanitize=address,undefined" |
| 43 | + "-fno-omit-frame-pointer" |
| 44 | + ) |
45 | 45 |
|
46 | | - list(APPEND NOT_MSVC_LINK_OPTIONS |
47 | | - "-fsanitize=address,undefined" |
48 | | - "-fno-omit-frame-pointer" |
49 | | - ) |
| 46 | + list(APPEND NOT_MSVC_LINK_OPTIONS |
| 47 | + "-fsanitize=address,undefined" |
| 48 | + "-fno-omit-frame-pointer" |
| 49 | + ) |
50 | 50 |
|
51 | | - list(APPEND MSVC_COMPILE_OPTIONS |
52 | | - "/WX" |
53 | | - "/Od" |
54 | | - # "/fsanitize=address" |
55 | | - ) |
56 | | -endif() |
| 51 | + list(APPEND MSVC_COMPILE_OPTIONS |
| 52 | + "/WX" |
| 53 | + "/Od" |
| 54 | + # "/fsanitize=address" |
| 55 | + ) |
| 56 | + endif() |
57 | 57 |
|
58 | | -target_compile_options(${TARGET} |
59 | | - PRIVATE |
| 58 | + target_compile_options(${project_name} |
| 59 | + PRIVATE |
60 | 60 | $<$<CXX_COMPILER_ID:MSVC>:${MSVC_COMPILE_OPTIONS}> |
61 | 61 | $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${NOT_MSVC_COMPILE_OPTIONS}> |
62 | | -) |
| 62 | + ) |
63 | 63 |
|
64 | | -target_link_options(${TARGET} |
65 | | - PUBLIC |
| 64 | + target_link_options(${project_name} |
| 65 | + PUBLIC |
66 | 66 | $<$<CXX_COMPILER_ID:MSVC>:${MSVC_LINK_OPTIONS}> |
67 | 67 | $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${NOT_MSVC_LINK_OPTIONS}> |
68 | | -) |
| 68 | + ) |
69 | 69 | endfunction() |
0 commit comments