-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
70 lines (56 loc) · 2.19 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
cmake_minimum_required(VERSION 3.10)
project(copypp VERSION 0.3.0 LANGUAGES CXX)
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(COPYPP_MASTER_PROJECT OFF)
# option(COPYPP_TEST "build copypp tests" OFF) # 是否开启 test 开关
# message(STATUS "CMAKE_CURRENT_SOURCE_DIR" ${CMAKE_CURRENT_SOURCE_DIR})
# message(STATUS "CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}")
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
# message(STATUS "CMAKE_CURRENT_SOURCE_DIR = CMAKE_SOURCE_DIR")
set(COPYPP_MASTER_PROJECT ON)
if (NOT DEFINED COPYPP_TEST)
set(COPYPP_TEST "build mathpp tests" ON)
endif()
# message(STATUS "CMake version: ${CMAKE_VERSION}")
# else()
# message(STATUS "CMAKE_CURRENT_SOURCE_DIR != CMAKE_SOURCE_DIR")
endif()
include(GNUInstallDirs)
add_library(copypp INTERFACE)
add_library(icurve::copypp ALIAS copypp)
set_target_properties(
copypp PROPERTIES VERSION ${${PROJECT_NAME}_VERSION}
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR})
target_include_directories(copypp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# 进行库安装
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
install(
TARGETS copypp
EXPORT ${TARGETS_EXPORT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION include
FRAMEWORK DESTINATION ".")
# 添加后续使用 cmake 导入的相关配置
include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME})
install(FILES "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
DESTINATION lib/cmake/${PROJECT_NAME})
install(EXPORT ${TARGETS_EXPORT_NAME}
NAMESPACE icurve::
DESTINATION "lib/cmake/${PROJECT_NAME}")
if (COPYPP_TEST)
message(STATUS "copypp tests...")
enable_testing()
add_subdirectory(test)
endif()