-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
86 lines (76 loc) · 2.51 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
cmake_minimum_required(VERSION 3.15)
project(clippson
VERSION 0.8.8
LANGUAGES CXX)
cmake_policy(SET CMP0169 OLD) # 3.28
set(CMAKE_VERBOSE_MAKEFILE ON)
include(CMakePrintHelpers)
include(FetchContent)
include(GNUInstallDirs)
cmake_print_variables(CMAKE_INSTALL_PREFIX)
function(import_env variable)
if(DEFINED ENV{${variable}})
set(${variable} $ENV{${variable}} PARENT_SCOPE)
endif()
endfunction()
function(git_fetch package version repo)
string(TOUPPER "${package}" upackage)
import_env("FETCHCONTENT_SOURCE_DIR_${upackage}")
if(IS_DIRECTORY "${FETCHCONTENT_SOURCE_DIR_${upackage}}")
set(tag "HEAD")
else()
set(tag "${version}")
endif()
cmake_print_variables(FETCHCONTENT_SOURCE_DIR_${upackage} tag)
set(FETCHCONTENT_QUIET OFF)
FetchContent_Declare(
${package}
GIT_REPOSITORY https://github.com/${repo}.git
GIT_TAG ${tag}
GIT_SHALLOW ON
)
FetchContent_GetProperties(${package})
if(NOT ${package}_POPULATED)
FetchContent_Populate(${package})
endif()
set(${package}_SOURCE_DIR ${${package}_SOURCE_DIR} PARENT_SCOPE)
cmake_print_variables(${package}_SOURCE_DIR)
endfunction()
git_fetch(clipp v1.2.3.1 heavywatal/clipp)
git_fetch(json v3.11.3 heavywatal/json)
set(clipp_srcs ${clipp_SOURCE_DIR}/include/clipp.h)
set(json_srcs ${json_SOURCE_DIR}/src/json.hpp ${json_SOURCE_DIR}/src/json_fwd.hpp)
foreach(src IN LISTS clipp_srcs json_srcs)
cmake_print_variables(src)
configure_file(${src} ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME} COPYONLY)
endforeach()
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-config
)
set(config_destination share/cmake/${PROJECT_NAME})
install(EXPORT ${PROJECT_NAME}-config
DESTINATION ${config_destination}
NAMESPACE ${PROJECT_NAME}::
)
set(version_file ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(${version_file}
COMPATIBILITY AnyNewerVersion
)
install(FILES ${version_file}
DESTINATION ${config_destination}
)
include(CTest)
if(BUILD_TESTING AND ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
add_subdirectory(test)
endif()