forked from pantor/inja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
122 lines (108 loc) · 3.03 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
cmake_minimum_required(VERSION 3.1)
##
## OPTIONS
##
option(BUILD_UNIT_TESTS "Build the unit tests" ON)
##
## HUNTER
##
option(HUNTER_ENABLED "Use hunter to manage dependencies" OFF)
if(HUNTER_ENABLED)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.19.156.tar.gz"
SHA1 "8d5e4635b137365e0d1ade4d60accf4e2bb41f0d"
)
endif()
##
## PROJECT
## name and version
##
project(inja LANGUAGES CXX VERSION 1.0.1)
set(INJA_VERSION ${PROJECT_VERSION})
##
## CONFIGURATION
##
# set(CMAKE_CXX_COMPILER g++-7)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(INJA_SOURCE_DIR src)
set(INJA_HEADER_INSTALL_DIR include)
if(WIN32 AND MSVC AND MSVC_VERSION LESS 1900)
message(FATAL_ERROR "[${PROJECT_NAME}] Visual Studio versions prior to 2015 do not support the noexcept keyword, which is used in the JSON library.")
endif()
##
## TESTS
## create and configure the unit test target
##
if(BUILD_UNIT_TESTS)
enable_testing()
add_subdirectory(test)
endif()
##
## TARGETS
## Build targets for the interface library
##
add_library(inja INTERFACE)
target_include_directories(inja INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INJA_SOURCE_DIR}>
$<INSTALL_INTERFACE:${INJA_HEADER_INSTALL_DIR}>
)
if(HUNTER_ENABLED) # Use Hunter to manage dependencies
# Add JSON package
hunter_add_package(nlohmann_json)
find_package(nlohmann_json CONFIG REQUIRED)
# Add dependencies to target
target_link_libraries(inja INTERFACE nlohmann_json)
else()
target_include_directories(inja INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test/thirdparty>
$<INSTALL_INTERFACE:${INJA_HEADER_INSTALL_DIR}>
)
endif()
##
## INSTALL
## install header files, generate and install cmake config files for find_package()
##
set(include_install_dir ${INJA_HEADER_INSTALL_DIR})
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
# Use:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
install(
TARGETS inja
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
install(
FILES ${INJA_SOURCE_DIR}/inja.hpp
DESTINATION "${include_install_dir}"
)
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)