generated from 106-inc/RepoTemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
83 lines (67 loc) · 2.07 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
cmake_minimum_required(VERSION 3.16)
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(
FATAL_ERROR
"In-source builds are disabled.
Please create a subfolder and use `cmake ..` inside it.
NOTE: cmake will now create CMakeCache.txt and CMakeFiles/*.
You must delete them, or cmake will refuse to work.")
endif()
project(leech)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -O2")
endif()
macro(check_compiler_version COMPILER VER)
if(CMAKE_CXX_COMPILER_ID STREQUAL ${COMPILER})
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${VER})
message(
FATAL_ERROR
"Insufficient ${COMPILER} version. Needed: ${VER}. Your: ${CMAKE_CXX_COMPILER_VERSION}"
)
endif()
endif()
endmacro()
check_compiler_version("GNU" "9.3.0")
check_compiler_version("Clang" "10.0.0")
include(cmake/list_dirs.cmake)
include(cmake/upd_tar_list.cmake)
include(cmake/comp_flags.cmake)
include(cmake/clang_format.cmake)
# indicate the docs build
option(BUILD_DOC "Build docs" OFF)
# indicate the tests build
option(BUILD_TESTS "Build tests" OFF)
# add -Werror option
option(ENABLE_WERROR "Enable -Werror option (CI)" OFF)
# Test running stuff
if(BUILD_TESTS)
enable_testing()
endif()
find_package(BISON 3.5 REQUIRED)
find_package(FLEX REQUIRED)
add_subdirectory(docs)
add_subdirectory(src)
add_subdirectory(tools)
add_subdirectory(test)
add_subdirectory(thirdparty)
message("Collected libs: ${LIBLIST}")
message("Collected tools: ${TOOLLIST}")
set(TARGETS)
list(APPEND TARGETS ${LIBLIST} ${TOOLLIST})
if(DEBUG_PRINT)
message("Debug print enabled!")
endif()
foreach(TARGET ${TARGETS})
target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_compile_features(${TARGET} PRIVATE cxx_std_20)
apply_compiler_flags(${TARGET} PUBLIC)
if(ENABLE_WERROR)
target_compile_options(${TARGET} PRIVATE -Werror)
endif()
if(DEBUG_PRINT)
target_compile_definitions(${TARGET} PRIVATE DEBUG_PRINT=1)
endif()
endforeach()
foreach(TOOL ${TOOLLIST})
target_link_libraries(${TOOL} PRIVATE ${LIBLIST})
endforeach()