-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
33 lines (27 loc) · 984 Bytes
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
cmake_minimum_required(VERSION 3.8)
set(WARNINGS_AS_ERRORS_FOR_MYLIB OFF CACHE BOOL "ON iff you want to treat warnings as errors")
add_library(mylib)
add_library(mylib::mylib ALIAS mylib)
target_compile_features(mylib PUBLIC cxx_std_20)
# ---Add source files---
if(WARNINGS_AS_ERRORS_FOR_MYLIB)
target_include_directories(mylib PUBLIC include)
else()
target_include_directories(mylib SYSTEM PUBLIC include)
endif()
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS src/*.cpp)
target_sources(mylib PRIVATE ${SRC_FILES})
# ---Set warning level---
if(MSVC)
target_compile_options(mylib PRIVATE /W4)
else()
target_compile_options(mylib PRIVATE -Wall -Wextra -Wpedantic -pedantic-errors -Wconversion -Wsign-conversion -Wimplicit-fallthrough)
endif()
# ---Maybe enable warnings as errors---
if(WARNINGS_AS_ERRORS_FOR_MYLIB)
if(MSVC)
target_compile_options(mylib PRIVATE /WX)
else()
target_compile_options(mylib PRIVATE -Werror)
endif()
endif()