-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
167 lines (129 loc) · 5.8 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
# Copyright 2024 John Buonagurio
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
cmake_minimum_required(VERSION 3.15)
# Enable CMAKE_MSVC_RUNTIME_LIBRARY.
cmake_policy(SET CMP0091 NEW)
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
file(TO_CMAKE_PATH "$ENV{VCPKG_ROOT}" VCPKG_ROOT)
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
unset(VCPKG_ROOT)
endif()
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
else()
# Use default triplet with static CRT and library linkage if not specified.
if(CMAKE_CL_64)
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")
elseif(CMAKE_CL_32)
set(VCPKG_TARGET_TRIPLET "x86-windows-static" CACHE STRING "")
endif()
endif()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "")
message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
message(STATUS "VCPKG_TARGET_TRIPLET: ${VCPKG_TARGET_TRIPLET}")
message(STATUS "CMAKE_MSVC_RUNTIME_LIBRARY: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
if(APPLE)
# Excel for Mac requires Universal Binary.
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
endif()
#-------------------------------------------------------------------------------
# Project
#-------------------------------------------------------------------------------
project(xll LANGUAGES CXX VERSION 1.0.0)
include(CTest)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BUILD_SHARED_LIBS ON)
# Common Options
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_TESTING "Build tests" OFF)
# Dependencies
find_package(Boost REQUIRED)
#-------------------------------------------------------------------------------
# Interface Target
#-------------------------------------------------------------------------------
add_library(xll INTERFACE)
add_library(xll::xll ALIAS xll)
target_compile_features(xll INTERFACE cxx_std_17)
target_include_directories(xll INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(xll INTERFACE Boost::boost)
#-------------------------------------------------------------------------------
# Tests
#-------------------------------------------------------------------------------
if(BUILD_TESTING)
add_executable(test_pstring ${CMAKE_CURRENT_SOURCE_DIR}/test/test_pstring.cpp)
add_executable(test_register ${CMAKE_CURRENT_SOURCE_DIR}/test/test_register.cpp)
add_executable(test_xloper ${CMAKE_CURRENT_SOURCE_DIR}/test/test_xloper.cpp)
target_link_libraries(test_pstring PRIVATE xll)
target_link_libraries(test_register PRIVATE xll)
target_link_libraries(test_xloper PRIVATE xll)
if(MSVC)
set_target_properties(test_pstring test_register test_xloper PROPERTIES COMPILE_FLAGS "/W4")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_target_properties(test_pstring test_register test_xloper PROPERTIES COMPILE_FLAGS "-Wall")
endif()
add_test(test_pstring test_pstring)
add_test(test_register test_register)
add_test(test_xloper test_xloper)
set_tests_properties(test_pstring test_register test_xloper PROPERTIES FAIL_REGULAR_EXPRESSION "[^a-z]Failed")
endif()
#-------------------------------------------------------------------------------
# Examples
#-------------------------------------------------------------------------------
if(BUILD_EXAMPLES)
# Minimal
add_library(minimal SHARED
${CMAKE_CURRENT_SOURCE_DIR}/src/examples/minimal/addin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/examples/minimal/addin.def)
target_link_libraries(minimal PRIVATE xll)
set_target_properties(minimal PROPERTIES OUTPUT_NAME "minimal" PREFIX "" SUFFIX ".xll")
# Generic
add_library(generic SHARED
${CMAKE_CURRENT_SOURCE_DIR}/src/examples/generic/addin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/examples/generic/addin.def)
target_link_libraries(generic PRIVATE xll)
set_target_properties(generic PROPERTIES OUTPUT_NAME "generic" PREFIX "" SUFFIX ".xll")
# Geodesic
find_package(GeographicLib CONFIG)
if(GeographicLib_FOUND)
add_library(geodesic SHARED
${CMAKE_CURRENT_SOURCE_DIR}/src/examples/geodesic/addin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/examples/geodesic/addin.def)
target_link_libraries(geodesic PRIVATE xll ${GeographicLib_LIBRARIES})
set_target_properties(geodesic PROPERTIES OUTPUT_NAME "geodesic" PREFIX "" SUFFIX ".xll")
endif()
endif()
#-------------------------------------------------------------------------------
# Install
#-------------------------------------------------------------------------------
set(XLL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/xll)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/xll
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS xll EXPORT xll-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(EXPORT xll-targets
FILE xll-targets.cmake
NAMESPACE xll::
DESTINATION ${XLL_CMAKE_DIR})
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/xll-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/xll-config.cmake
INSTALL_DESTINATION ${XLL_CMAKE_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xll-config.cmake
DESTINATION ${XLL_CMAKE_DIR})
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/xll-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
ARCH_INDEPENDENT)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xll-config-version.cmake
DESTINATION ${XLL_CMAKE_DIR})