-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
183 lines (151 loc) · 6.56 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
############################################################################
# Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and #
# Martin Renou #
# #
# Distributed under the terms of the BSD 3-Clause License. #
# #
# The full license is in the file LICENSE, distributed with this software. #
############################################################################
cmake_minimum_required(VERSION 3.1)
project(xplugin)
set(XPLUGIN_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
# cmake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# helper function to add plugins
set(XPLUGIN_XPLUGIN_LIBRARY xplugin_plugin)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/xplugin_add_xplugin.cmake)
# helper functions(s) for emscripten
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/xplugin_emscripten_utils.cmake)
################################################################
# Options
################################################################
OPTION(XPLUGIN_BUILD_TESTS "Build the test suite" ON)
OPTION(XPLUGIN_BUILD_EXAMPLES "Build the examples" ON)
OPTION(XPLUGIN_BUILD_DOCS "Build the documentation" OFF)
################################################################
# Versionning
################################################################
file(STRINGS "${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_config.hpp" xplugin_version_defines
REGEX "#define XPLUGIN_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${xplugin_version_defines})
if(ver MATCHES "#define XPLUGIN_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(XPLUGIN_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(${PROJECT_NAME}_VERSION
${XPLUGIN_VERSION_MAJOR}.${XPLUGIN_VERSION_MINOR}.${XPLUGIN_VERSION_PATCH})
message(STATUS "Building xplugin v${${PROJECT_NAME}_VERSION}")
################################################################
# Headers
################################################################
set(XPLUGIN_HEADERS
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_config.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xshared_library.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xfactory.hpp
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_registry.hpp
)
################################################################
# Emscripten related
################################################################
xplugin_add_emscripten_flags()
################################################################
# Interface libraries
################################################################
add_library(xplugin INTERFACE)
add_library(xplugin_host INTERFACE)
add_library(xplugin_plugin INTERFACE)
target_link_libraries(xplugin_host INTERFACE xplugin)
target_link_libraries(xplugin_plugin INTERFACE xplugin)
################################################################
# Dependencies
################################################################
if((APPLE OR UNIX OR LINUX ) AND NOT EMSCRIPTEN)
target_link_libraries(xplugin_host INTERFACE ${CMAKE_DL_LIBS})
endif()
################################################################
# Flags
################################################################
if(EMSCRIPTEN)
# compiler flags
set_target_properties(xplugin_host PROPERTIES COMPILE_FLAGS "-s MAIN_MODULE=1")
set_target_properties(xplugin_plugin PROPERTIES COMPILE_FLAGS "-s SIDE_MODULE=1")
set_target_properties(xplugin_host PROPERTIES LINK_FLAGS "-s MAIN_MODULE=1")
set_target_properties(xplugin_plugin PROPERTIES LINK_FLAGS "-s SIDE_MODULE=1")
endif()
set_property(TARGET xplugin PROPERTY CXX_STANDARD 17)
target_compile_features(xplugin INTERFACE cxx_std_17)
target_include_directories(xplugin INTERFACE $<BUILD_INTERFACE:${XPLUGIN_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(xplugin_plugin INTERFACE $<BUILD_INTERFACE:${XPLUGIN_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
################################################################
# Tests
################################################################
if(XPLUGIN_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
################################################################
# Examples
################################################################
if(XPLUGIN_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
################################################################
# Documentation
################################################################
if(XPLUGIN_BUILD_DOCS)
add_subdirectory(docs)
endif()
################################################################
# Installation
################################################################
if (APPLE)
set_target_properties(xplugin PROPERTIES
MACOSX_RPATH ON
)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib; ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
elseif(NOT EMSCRIPTEN)
set_target_properties(xplugin PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib; ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(XPLUGIN_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xpluginConfig.cmake")
# install the targets
install(
TARGETS xplugin xplugin_host xplugin_plugin
EXPORT xpluginTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
# install the targets file
INSTALL(
EXPORT xpluginTargets
FILE xpluginTargets.cmake
DESTINATION "${XPLUGIN_CMAKECONFIG_INSTALL_DIR}"
NAMESPACE xplugin::
)
# configure the config file
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/xpluginConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/xpluginConfig.cmake
INSTALL_DESTINATION ${XPLUGIN_CMAKECONFIG_INSTALL_DIR}
)
# the config
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/xpluginConfig.cmake"
DESTINATION "${XPLUGIN_CMAKECONFIG_INSTALL_DIR}"
)
# the headers
install(DIRECTORY ${XPLUGIN_INCLUDE_DIR}/xplugin
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp")
# install cmake file
install(FILES cmake/xplugin_add_xplugin.cmake
DESTINATION ${XPLUGIN_CMAKECONFIG_INSTALL_DIR})