forked from pantor/inja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
189 lines (136 loc) · 4.79 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
cmake_minimum_required(VERSION 3.5)
project(inja LANGUAGES CXX VERSION 2.0.0)
option(INJA_USE_EMBEDDED_JSON "Use the shipped json header if not available on the system" ON)
option(INJA_INSTALL "Generate install targets for inja" ON)
option(INJA_EXPORT "Export the current build tree to the package registry" ON)
option(BUILD_TESTING "Build unit tests" ON)
option(BUILD_BENCHMARK "Build benchmark" ON)
option(COVERALLS "Generate coveralls data" OFF)
set(INJA_INSTALL_INCLUDE_DIR "include")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
add_library(inja INTERFACE)
add_library(pantor::inja ALIAS inja)
target_include_directories(inja INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INJA_INSTALL_INCLUDE_DIR}>
)
target_compile_features(inja INTERFACE cxx_std_11)
set(INJA_PACKAGE_USE_EMBEDDED_JSON OFF)
if(INJA_USE_EMBEDDED_JSON)
find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
set(INJA_PACKAGE_USE_EMBEDDED_JSON ON)
add_library(nlohmann_json INTERFACE)
add_library(pantor::nlohmann_json ALIAS nlohmann_json)
target_include_directories(nlohmann_json INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/include>
$<INSTALL_INTERFACE:${INJA_INSTALL_INCLUDE_DIR}/inja/json/include>
)
target_compile_features(nlohmann_json INTERFACE cxx_std_11)
install(TARGETS nlohmann_json EXPORT injaTargets)
set(INJA_SELECTED_JSON_LIBRARY "pantor::nlohmann_json")
else()
set(INJA_SELECTED_JSON_LIBRARY "nlohmann_json::nlohmann_json")
endif()
else()
# If target already exists, e.g. by git submodules
if(TARGET nlohmann_json)
set(INJA_SELECTED_JSON_LIBRARY "nlohmann_json::nlohmann_json")
else()
find_package(nlohmann_json REQUIRED)
set(INJA_SELECTED_JSON_LIBRARY "nlohmann_json::nlohmann_json")
endif()
endif()
target_link_libraries(inja INTERFACE ${INJA_SELECTED_JSON_LIBRARY})
execute_process(COMMAND scripts/update_single_include.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
if(BUILD_TESTING)
enable_testing()
add_executable(inja_test
test/unit.cpp
test/unit-files.cpp
test/unit-renderer.cpp
)
target_link_libraries(inja_test PRIVATE inja)
add_test(inja_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/inja_test)
add_library(single_inja INTERFACE)
target_compile_features(single_inja INTERFACE cxx_std_11)
target_include_directories(single_inja INTERFACE single_include include third_party/include)
add_executable(single_inja_test
test/unit.cpp
test/unit-files.cpp
test/unit-renderer.cpp
)
target_link_libraries(single_inja_test PRIVATE single_inja)
add_test(single_inja_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/single_inja_test)
endif()
if(BUILD_BENCHMARK)
add_executable(inja_benchmark test/benchmark.cpp)
target_link_libraries(inja_benchmark PRIVATE inja)
endif()
if(COVERALLS)
include(Coveralls)
coveralls_turn_on_coverage()
file(GLOB_RECURSE COVERAGE_SRCS include/inja/*.hpp)
# set(COVERAGE_SRCS test/unit.cpp test/unit-renderer.cpp include/inja)
coveralls_setup("${COVERAGE_SRCS}" OFF) # If we should upload.
endif()
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/injaConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
# build tree package config
configure_file(
cmake/config/injaBuildConfig.cmake.in
injaConfig.cmake
@ONLY
)
install(TARGETS inja EXPORT injaTargets)
export(
EXPORT injaTargets
NAMESPACE pantor::
FILE "${CMAKE_CURRENT_BINARY_DIR}/injaTargets.cmake"
)
# build tree package config
configure_file(
cmake/config/injaBuildConfig.cmake.in
injaConfig.cmake
@ONLY
)
if(INJA_INSTALL)
set(INJA_CONFIG_PATH "lib/cmake/inja")
# install tree package config
configure_package_config_file(
cmake/config/injaConfig.cmake.in
${INJA_CONFIG_PATH}/injaConfig.cmake
INSTALL_DESTINATION ${INJA_CONFIG_PATH}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(DIRECTORY include/inja DESTINATION ${INJA_INSTALL_INCLUDE_DIR} FILES_MATCHING PATTERN "*.hpp")
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/include/nlohmann/json.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/include/nlohmann/LICENSE.MIT"
DESTINATION "${INJA_INSTALL_INCLUDE_DIR}/inja/json/include/nlohmann"
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${INJA_CONFIG_PATH}/injaConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/injaConfigVersion.cmake"
DESTINATION ${INJA_CONFIG_PATH}
)
install(
EXPORT injaTargets FILE injaTargets.cmake
NAMESPACE pantor::
DESTINATION ${INJA_CONFIG_PATH}
)
endif()
if(INJA_EXPORT)
export(PACKAGE inja)
endif()