-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
122 lines (101 loc) · 3.81 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.20)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(STRINGS "include/asbind20/asbind.hpp" asbind20_version_major_line REGEX "^#define ASBIND20_VERSION_MAJOR [0-9]+$")
file(STRINGS "include/asbind20/asbind.hpp" asbind20_version_minor_line REGEX "^#define ASBIND20_VERSION_MINOR [0-9]+$")
file(STRINGS "include/asbind20/asbind.hpp" asbind20_version_patch_line REGEX "^#define ASBIND20_VERSION_PATCH [0-9]+$")
string(REGEX REPLACE "^#define ASBIND20_VERSION_MAJOR ([0-9]+)$" "\\1" asbind20_version_major "${asbind20_version_major_line}")
string(REGEX REPLACE "^#define ASBIND20_VERSION_MINOR ([0-9]+)$" "\\1" asbind20_version_minor "${asbind20_version_minor_line}")
string(REGEX REPLACE "^#define ASBIND20_VERSION_PATCH ([0-9]+)$" "\\1" asbind20_version_patch "${asbind20_version_patch_line}")
unset(asbind20_version_major_line)
unset(asbind20_version_minor_line)
unset(asbind20_version_patch_line)
message("asbind20 v${asbind20_version_major}.${asbind20_version_minor}.${asbind20_version_patch}")
project(
asbind20
VERSION ${asbind20_version_major}.${asbind20_version_minor}.${asbind20_version_patch}
LANGUAGES CXX
)
find_package(Threads REQUIRED)
find_package(Angelscript 2.37.0 CONFIG REQUIRED)
add_library(asbind20 STATIC)
# Enable warnings for development
target_compile_options(asbind20 PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
)
# Add an ALIAS target for using the library by add_subdirectory()
add_library(asbind20::asbind20 ALIAS asbind20)
file(GLOB asbind20_src "include/*.hpp" "src/*.cpp")
option(asbind_build_ext "Build extensions" ON)
include(GNUInstallDirs)
option(asbind_build_test "Build tests" OFF)
mark_as_advanced(asbind_build_test)
if(${asbind_build_test})
message(STATUS "Fetching GoogleTest v1.14.0 from GitHub")
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
)
set(BUILD_GMOCK OFF)
set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(googletest)
enable_testing()
endif()
if(${asbind_build_ext})
add_subdirectory(ext)
endif()
target_sources(asbind20 PRIVATE ${asbind20_src})
target_include_directories(asbind20 PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(asbind20 PUBLIC Threads::Threads)
target_link_libraries(asbind20 PUBLIC Angelscript::angelscript)
target_compile_definitions(asbind20
PRIVATE $<$<CONFIG:Debug>:ASBIND20_DEBUG=1>
)
install(
TARGETS asbind20
EXPORT asbind20Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl"
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"asbind20ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/asbind20Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/asbind20Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/asbind20
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/asbind20Config.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/asbind20
)
install(
EXPORT asbind20Targets
FILE asbind20Targets.cmake
NAMESPACE asbind20::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/asbind20
)
if(${asbind_build_test})
add_subdirectory(test)
endif()
option(asbind_build_example "Build examples" OFF)
if(${asbind_build_example})
add_subdirectory(example)
endif()