-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
127 lines (107 loc) · 3.87 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
cmake_minimum_required(VERSION 3.11)
project(exdir-cpp
VERSION 0.0.1
LANGUAGES CXX
)
include(CheckCXXCompilerFlag)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(FetchContent)
#===============================================================================
# Options
option(EXDIR_CPP_SHARED "Build Exdir-CPP as a shared library" OFF)
option(EXDIR_CPP_INSTALL "Install the Exdir-CPP library and header files" ON)
option(EXDIR_CPP_EXAMPLE "Build Exdir-CPP example" OFF)
#===============================================================================
# Get YAML-CPP version 0.8.0
message(STATUS "Downloading yaml-cpp 0.8.0")
FetchContent_Declare(yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG 0.8.0
)
if (EXDIR_CPP_SHARED)
set(YAML_CPP_BUILD_SHARED_LIBS OFF CACHE BOOL "Build yaml-cpp shared library")
endif()
set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Enable testing")
set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Enable parse tools")
set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "Enable contrib stuff in library")
if (NOT EXDIR_CPP_INSTALL)
set(YAML_CPP_INSTALL OFF CACHE BOOL "Enable generation of install target")
endif()
FetchContent_MakeAvailable(yaml-cpp)
#===============================================================================
# Get NDArray
message(STATUS "Downloading NDArray")
FetchContent_Declare(NDArray
GIT_REPOSITORY https://github.com/HunterBelanger/ndarray.git
GIT_TAG master
)
set(NDARRAY_INSTALL OFF CACHE BOOL "Install NDArray")
FetchContent_MakeAvailable(NDArray)
set(EXDIR_CPP_SOURCE_FILES ${EXDIR_CPP_SOURCE_FILES}
src/object.cpp
src/group.cpp
src/raw.cpp
src/file.cpp
src/dataset.cpp
)
if (EXDIR_CPP_SHARED)
add_library(exdir-cpp SHARED ${EXDIR_CPP_SOURCE_FILES})
else()
add_library(exdir-cpp STATIC ${EXDIR_CPP_SOURCE_FILES})
endif()
# Add alias to make more friendly with FetchConent
add_library(Exdir::exdir-cpp ALIAS exdir-cpp)
target_link_libraries(exdir-cpp PUBLIC yaml-cpp NDArray::NDArray)
target_include_directories(exdir-cpp
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${YAML_CPP_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:${YAML_CPP_INCLUDE_DIR}>
)
target_compile_options(exdir-cpp
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-W -Wall -Wextra -Wconversion -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:/W3 /wd4127 /wd4355>
)
target_compile_features(exdir-cpp PUBLIC cxx_std_17)
if (EXDIR_CPP_EXAMPLE)
add_subdirectory(example)
endif()
set_target_properties(exdir-cpp PROPERTIES
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
PROJECT_LABEL "exdir-cpp"
)
if(EXDIR_CPP_INSTALL)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/exdir-cppConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/exdir-cppConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/exdir-cpp
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/exdir-cppConfigVersion.cmake"
VERSION "${exdir-cpp_VERSION}"
COMPATIBILITY SameMinorVersion
)
install(TARGETS exdir-cpp yaml-cpp NDArray
EXPORT exdir-cppTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/exdir
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT exdir-cppTargets
FILE exdir-cppTargets.cmake
NAMESPACE Exdir::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/exdir-cpp
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/exdir-cppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/exdir-cppConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/exdir-cpp
)
endif()