forked from ianpatt/common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
103 lines (82 loc) · 1.65 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
cmake_minimum_required(VERSION 3.18)
# ---- Project ----
set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Z7 /Ob0 /Od /RTC1" CACHE STRING "")
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "")
project(
common
LANGUAGES CXX
)
# ---- Include guards ----
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()
# ---- Add source files ----
include(cmake/headerlist.cmake)
include(cmake/sourcelist.cmake)
source_group(
${PROJECT_NAME}
FILES
${headers}
${sources}
)
# ---- Create library ----
add_library(
${PROJECT_NAME}
STATIC
${headers}
${sources}
)
add_library(xse::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_features(
${PROJECT_NAME}
PUBLIC
cxx_std_11
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_precompile_headers(
${PROJECT_NAME}
PUBLIC
common/IPrefix.h
)
# ---- Create an installable target ----
include(GNUInstallDirs)
install(
TARGETS
${PROJECT_NAME}
EXPORT
${PROJECT_NAME}-targets
)
install(
FILES
${headers}
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
configure_file(
cmake/config.cmake.in
${PROJECT_NAME}-config.cmake
@ONLY
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(
EXPORT
${PROJECT_NAME}-targets
NAMESPACE
xse::
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)