forked from 106-inc/sim2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
90 lines (74 loc) · 2.44 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
84
85
86
87
88
89
90
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(SIM2022)
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" "10.3.0")
check_compiler_version("MSVC" "14.32.31326")
check_compiler_version("Clang" "12.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" ON)
# add -Werror option
option(ENABLE_WERROR "Enable -Werror option (CI)" OFF)
# enable spdlog
option(ENABLE_LOG "Enable spdlog" OFF)
# Test running stuff
if(BUILD_TESTS)
enable_testing()
endif()
find_package(spdlog REQUIRED)
message("Found package: spdlog")
find_package( Python3 3.10 COMPONENTS Interpreter Development REQUIRED)
message("Found package: python")
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})
foreach(TARGET ${TARGETS})
target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_include_directories(${TARGET}
PUBLIC ${CMAKE_BINARY_DIR}/include/codegen)
add_dependencies(${TARGET} DecoderGenerator)
target_compile_features(${TARGET} PRIVATE cxx_std_20)
target_link_libraries(${TARGET} PRIVATE spdlog::spdlog)
apply_compiler_flags(${TARGET} PUBLIC)
if(ENABLE_WERROR)
target_compile_options(${TARGET} PRIVATE -Werror)
endif()
if(ENABLE_LOG)
target_compile_definitions(${TARGET} PUBLIC -DSPDLOG=1)
endif()
endforeach()
foreach(TOOL ${TOOLLIST})
target_link_libraries(${TOOL} PRIVATE ${LIBLIST})
if(ENABLE_LOG)
target_compile_definitions(${TOOL} PRIVATE SPDLOG=1)
endif()
endforeach()
add_compile_options(-g3 -O3)