-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
CMakeLists.txt
129 lines (113 loc) · 3.19 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
cmake_minimum_required(VERSION 3.16...3.21)
# set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc.
# You can later set fine-grained standards for each target using `target_compile_features`
set(CMAKE_CXX_STANDARD 20)
### Add project_options
# include(FetchContent)
# FetchContent_Declare(_project_options URL https://github.com/cpp-best-practices/project_options/archive/refs/heads/main.zip)
# FetchContent_MakeAvailable(_project_options)
# include(${_project_options_SOURCE_DIR}/Index.cmake)
include(../src/Index.cmake)
run_vcpkg()
project(
myproj
VERSION 0.2.0
LANGUAGES CXX C)
# Initialize project_options
# uncomment the options to enable them
project_options(
ENABLE_CACHE
# ENABLE_CONAN
# WARNINGS_AS_ERRORS
ENABLE_CPPCHECK
ENABLE_CLANG_TIDY
# ENABLE_INCLUDE_WHAT_YOU_USE
# ENABLE_COVERAGE
# ENABLE_PCH
# PCH_HEADERS <Eigen/Dense> <fmt/core.h> <vector> <utility> <string> <string_view>
ENABLE_DOXYGEN
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
# ENABLE_SANITIZER_ADDRESS
# ENABLE_SANITIZER_LEAK
# ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
# ENABLE_SANITIZER_THREAD
# ENABLE_SANITIZER_MEMORY
# CLANG_WARNINGS "-Weverything"
)
# NOTE: project_options and project_warnings are defined inside project_options
# Executable
add_executable(main ./src/main/main.cpp)
target_link_libraries(main PRIVATE project_options project_warnings)
## dependencies
set(DEPENDENCIES_CONFIGURED fmt Eigen3)
foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED})
find_package(${DEPENDENCY} CONFIG REQUIRED)
endforeach()
target_link_system_libraries(
main
PRIVATE
fmt::fmt
Eigen3::Eigen)
## tests
enable_testing()
add_test(NAME main COMMAND main)
# Header-only library
add_library(lib INTERFACE)
set(INCLUDE_DIR "include")
target_include_directories(lib INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:./${CMAKE_INSTALL_INCLUDEDIR}>") # TODO(refactor)
target_link_libraries(lib INTERFACE project_options project_warnings)
target_link_system_libraries(
lib
INTERFACE
fmt::fmt
Eigen3::Eigen)
# Library
add_library(lib2 "./src/mylib2/lib.cpp")
set(INCLUDE_DIR2 "include")
target_include_directories(lib2 INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR2}>"
"$<INSTALL_INTERFACE:./${CMAKE_INSTALL_INCLUDEDIR}>") # TODO(refactor)
target_link_libraries(lib2 INTERFACE project_options project_warnings)
target_link_system_libraries(
lib2
PRIVATE
fmt::fmt
Eigen3::Eigen)
# package everything automatically
package_project(
# NAME
# myproj
# TARGETS
# main
# lib
# project_warnings
# project_options
INTERFACE_DEPENDENCIES_CONFIGURED
${DEPENDENCIES_CONFIGURED}
INTERFACE_INCLUDES
${INCLUDE_DIR})
# package separately (for testing)
package_project(
NAME
myproj_header_only_lib
TARGETS
lib
INTERFACE_DEPENDENCIES_CONFIGURED
${DEPENDENCIES_CONFIGURED}
INTERFACE_INCLUDES
${INCLUDE_DIR})
package_project(
NAME
myproj_lib
TARGETS
lib2
INTERFACE_INCLUDES
${INCLUDE_DIR2})
package_project(
NAME
myproj_main
TARGETS
main)