-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
128 lines (111 loc) · 2.87 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
cmake_minimum_required(VERSION 3.15)
project(bustache VERSION 0.1.0 LANGUAGES CXX)
option(BUSTACHE_ENABLE_TESTING "Enable testing of the bustache library." OFF)
option(BUSTACHE_USE_FMT "Use fmtlib." OFF)
message(STATUS "Started CMake for ${PROJECT_NAME} v${PROJECT_VERSION}...\n")
add_library(
${PROJECT_NAME}
src/format.cpp
src/render.cpp
)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PRIVATE BUSTACHE_EXPORT INTERFACE BUSTACHE_SHARED)
endif()
# Allow usage of header files in the `src` directory, but only for utilities
target_include_directories(
${PROJECT_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# Identify and link with the specific "packages" the project uses
#find_package(package_name package_version REQUIRED package_type [other_options])
#target_link_libraries(
# ${PROJECT_NAME}
# PUBLIC
# dependency1 ...
# PRIVATE
# dependency2 ...
# ${PROJECT_NAME}_PROJECT_OPTIONS
# ${PROJECT_NAME}_PROJECT_WARNINGS
#)
if(BUSTACHE_USE_FMT)
find_package(fmt REQUIRED)
target_link_libraries(
${PROJECT_NAME}
PUBLIC
fmt::fmt
)
target_compile_definitions(
${PROJECT_NAME}
PUBLIC
BUSTACHE_USE_FMT
)
endif()
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
include(GNUInstallDirs)
# Install the library and headers.
install(
TARGETS
${PROJECT_NAME}
EXPORT
${PROJECT_NAME}-targets
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION
include
PUBLIC_HEADER DESTINATION
include
)
# Install version, config and target files.
install(
EXPORT
${PROJECT_NAME}-targets
FILE
${PROJECT_NAME}-targets.cmake
NAMESPACE
${PROJECT_NAME}::
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
# Install the `include` directory
install(
DIRECTORY
include/${PROJECT_NAME}
DESTINATION
include
)
# Quick `config-version.cmake` creation
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${PROJECT_NAME}-config-version.cmake
VERSION
${PROJECT_VERSION}
COMPATIBILITY
SameMajorVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
# Unit testing setup
if(BUSTACHE_ENABLE_TESTING)
enable_testing()
add_subdirectory(test)
endif()