-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
230 lines (210 loc) · 9.47 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Copyright (c) Prophesee S.A.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
cmake_minimum_required(VERSION 3.14.0)
cmake_policy(SET CMP0087 NEW)
project(hdf5_ecf VERSION 1.0.1)
set(HDF5_ECF_PROJECT_VERSION "${PROJECT_VERSION}" CACHE INTERNAL "")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release
RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
set(HDF5_ECF_PLUGIN_BUILD_PATH "${CMAKE_BINARY_DIR}/lib/hdf5/plugin" CACHE INTERNAL "" FORCE)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND NOT CMAKE_INSTALL_PREFIX)
if(APPLE)
set(HDF5_ECF_PLUGIN_INSTALL_PATH "/opt/local/lib/hdf5/" CACHE INTERNAL "" FORCE)
elseif(WIN32)
set(HDF5_ECF_PLUGIN_INSTALL_PATH "$ENV{ALLUSERSPROFILE}/hdf5/lib/plugin/" CACHE INTERNAL "" FORCE)
else()
set(HDF5_ECF_PLUGIN_INSTALL_PATH "/usr/local/hdf5/lib/plugin" CACHE INTERNAL "" FORCE)
endif()
else(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND NOT CMAKE_INSTALL_PREFIX)
set(HDF5_ECF_PLUGIN_INSTALL_PATH "lib/hdf5/plugin" CACHE INTERNAL "" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND NOT CMAKE_INSTALL_PREFIX)
if(WIN32)
set(CMAKE_DEBUG_POSTFIX "_d")
endif()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(HDF5 REQUIRED)
# libhdf5_ecf_codec
add_library(hdf5_ecf_codec SHARED ecf_codec.cpp)
include(CTest)
if (BUILD_TESTING)
find_package(GTest REQUIRED)
add_executable(gtest_ecf_codec ecf_codec_test.cpp)
target_link_libraries(gtest_ecf_codec PRIVATE hdf5_ecf_codec GTest::gtest GTest::gtest_main)
add_test(
NAME ecf_codec
COMMAND $<TARGET_FILE:gtest_ecf_codec> --gtest_color=yes --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/gtest/ecf_codec.xml
)
endif ()
# targets generation and installation
include(GenerateExportHeader)
generate_export_header(hdf5_ecf_codec BASE_NAME ecf_codec)
target_include_directories(hdf5_ecf_codec
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/..>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:include>"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ecf_codec_export.h"
DESTINATION "include/hdf5_ecf"
COMPONENT hdf5-ecf-codec-dev
)
# LICENSE
install(FILES "${PROJECT_SOURCE_DIR}/LICENSE"
DESTINATION "share/hdf5_ecf"
COMPONENT hdf5-ecf-codec-dev
)
set_target_properties(hdf5_ecf_codec
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
install(TARGETS hdf5_ecf_codec
EXPORT hdf5_ecf-targets
RUNTIME
DESTINATION "bin"
COMPONENT hdf5-ecf-codec-lib
ARCHIVE
DESTINATION "lib"
COMPONENT hdf5-ecf-codec-lib
LIBRARY
DESTINATION "lib"
COMPONENT hdf5-ecf-codec-lib
NAMELINK_SKIP
)
install(TARGETS hdf5_ecf_codec
EXPORT hdf5_ecf-targets
LIBRARY
DESTINATION "lib"
COMPONENT hdf5-ecf-codec-dev
NAMELINK_ONLY
)
install(FILES ecf_codec.h
DESTINATION "include/hdf5_ecf"
COMPONENT hdf5-ecf-codec-dev
)
export(EXPORT hdf5_ecf-targets FILE hdf5_ecf-targets.cmake)
install(EXPORT hdf5_ecf-targets
FILE hdf5_ecf-targets.cmake
DESTINATION share/cmake/hdf5_ecf
COMPONENT hdf5-ecf-codec-dev
)
# Create and install configuration files
include(CMakePackageConfigHelpers)
configure_package_config_file(
"hdf5_ecf-config.cmake.in"
"hdf5_ecf-config.cmake"
INSTALL_DESTINATION share/cmake/hdf5_ecf
)
write_basic_package_version_file(
"hdf5_ecf-config-version.cmake"
COMPATIBILITY ExactVersion
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hdf5_ecf-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/hdf5_ecf-config-version.cmake"
DESTINATION share/cmake/hdf5_ecf
COMPONENT hdf5-ecf-codec-dev
)
# HDF5 ECF filter
install(FILES ecf_h5filter.h
DESTINATION "include/hdf5_ecf"
COMPONENT hdf5-plugin-ecf-dev
)
# HDF5 ECF plugin
add_library(hdf5_ecf_plugin SHARED ecf_h5plugin.cpp)
set_target_properties(hdf5_ecf_plugin PROPERTIES OUTPUT_NAME H5Zecf)
target_link_libraries(hdf5_ecf_plugin PUBLIC hdf5_ecf_codec ${HDF5_LIBRARIES})
target_include_directories(hdf5_ecf_plugin PUBLIC ${HDF5_INCLUDE_DIRS})
file(MAKE_DIRECTORY "${HDF5_ECF_PLUGIN_BUILD_PATH}")
add_custom_command(
TARGET hdf5_ecf_plugin POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:hdf5_ecf_plugin>" "${HDF5_ECF_PLUGIN_BUILD_PATH}"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:hdf5_ecf_codec>" "${HDF5_ECF_PLUGIN_BUILD_PATH}"
)
install(TARGETS hdf5_ecf_plugin
RUNTIME DESTINATION "${HDF5_ECF_PLUGIN_INSTALL_PATH}" COMPONENT hdf5-plugin-ecf-local-install
LIBRARY DESTINATION "${HDF5_ECF_PLUGIN_INSTALL_PATH}" COMPONENT hdf5-plugin-ecf-local-install
)
install(CODE "message(NOTICE \"\n\nNote:\n=====\nTo use the HDF5 ECF plugin, it may be necessary to append the path '${HDF5_ECF_PLUGIN_INSTALL_PATH}' to the HDF5_PLUGIN_PATH environment variable in your session or permanently.\n\")"
COMPONENT hdf5-plugin-ecf-local-install
)
set (HDF5_ECF_PLUGIN_DEB_INSTALL_PATH "/usr/lib/${CMAKE_CXX_LIBRARY_ARCHITECTURE}/hdf5/plugins" CACHE INTERNAL "" FORCE)
if (UNIX AND NOT APPLE)
find_program(_lsb_release_exec lsb_release)
execute_process(COMMAND ${_lsb_release_exec} -cs
OUTPUT_VARIABLE _ubuntu_platform
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if ("${_ubuntu_platform}" STREQUAL "jammy")
set (HDF5_ECF_PLUGIN_DEB_INSTALL_PATH "/usr/lib/${CMAKE_CXX_LIBRARY_ARCHITECTURE}/hdf5/serial/plugins" CACHE INTERNAL "" FORCE)
endif ()
endif (UNIX AND NOT APPLE)
install(TARGETS hdf5_ecf_plugin
RUNTIME DESTINATION ${HDF5_ECF_PLUGIN_DEB_INSTALL_PATH} COMPONENT hdf5-plugin-ecf EXCLUDE_FROM_ALL
LIBRARY DESTINATION ${HDF5_ECF_PLUGIN_DEB_INSTALL_PATH} COMPONENT hdf5-plugin-ecf EXCLUDE_FROM_ALL
)
file(
WRITE "${CMAKE_CURRENT_BINARY_DIR}/postinst" "\
#!/usr/bin/env sh\n\
echo \"\"\n\
echo \"Note:\"\n\
echo \"=====\"\n\
echo \"To use the HDF5 ECF plugin, it may be necessary to run 'set HDF5_PLUGIN_PATH=${HDF5_ECF_PLUGIN_DEB_INSTALL_PATH}:\\$\{HDF5_PLUGIN_PATH\}' in your session or shell initialization script.\"\n\
echo \"\"\n\
")
file(
COPY "${CMAKE_CURRENT_BINARY_DIR}/postinst"
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
if (WIN32)
# on windows, we put the DLL next to the plugin with a symlink to avoid having to mess with PATH
install(CODE
"execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink \"$<TARGET_FILE:hdf5_ecf_codec>\" \"${HDF5_ECF_PLUGIN_INSTALL_PATH}/$<TARGET_FILE_NAME:hdf5_ecf_codec>\")"
)
endif()
# CPack
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "")
set(CPACK_PACKAGE_VENDOR "Prophesee")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION_FULL})
set(CPACK_DEBIAN_ARCHIVE_TYPE "gnutar") # Variable introduced in cmake 3.7 (see https://cmake.org/cmake/help/v3.8/release/3.7.html#cpack)
# Follow Debian policy on control files' permissions
# cf https://cmake.org/cmake/help/v3.10/module/CPackDeb.html#variable:CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "[email protected] Copyright (c) Prophesee S.A.") #required
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE https://support.prophesee.ai)
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_COMPONENTS_ALL hdf5-ecf-codec-lib hdf5-ecf-codec-dev hdf5-plugin-ecf hdf5-plugin-ecf-dev)
# Library
set(CPACK_COMPONENT_HDF5-ECF-CODEC-LIB_DESCRIPTION "HDF5 ECF Codec library")
set(CPACK_DEBIAN_HDF5-ECF-CODEC-LIB_FILE_NAME "hdf5-ecf-codec-lib-${PROJECT_VERSION}.deb")
set(CPACK_DEBIAN_HDF5-ECF-CODEC-LIB_PACKAGE_NAME "hdf5-ecf-codec-lib")
# Dev
set(CPACK_COMPONENT_HDF5-ECF-CODEC-DEV_DESCRIPTION "HDF5 ECF Codec (C++) files")
set(CPACK_COMPONENT_HDF5-ECF-CODEC-DEV_DEPENDS hdf5-ecf-codec-lib)
set(CPACK_DEBIAN_HDF5-ECF-CODEC-DEV_FILE_NAME "hdf5-ecf-codec-dev-${PROJECT_VERSION}.deb")
set(CPACK_DEBIAN_HDF5-ECF-CODEC-DEV_PACKAGE_NAME "hdf5-ecf-codec-dev")
set(CPACK_DEBIAN_HDF5-ECF-CODEC-DEV_PACKAGE_DEPENDS libhdf5-dev)
# Plugin
set(CPACK_COMPONENT_HDF5-PLUGIN-ECF_DESCRIPTION "HDF5 ECF Plugin")
set(CPACK_DEBIAN_HDF5-PLUGIN-ECF_FILE_NAME "hdf5-plugin-ecf-${PROJECT_VERSION}.deb")
set(CPACK_DEBIAN_HDF5-PLUGIN-ECF_PACKAGE_NAME "hdf5-plugin-ecf")
set(CPACK_COMPONENT_HDF5-PLUGIN-ECF_DEPENDS hdf5-ecf-codec-lib)
set(CPACK_DEBIAN_HDF5-PLUGIN-ECF_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_HDF5-PLUGIN-ECF_PACKAGE_CONTROL_EXTRA};${CMAKE_CURRENT_BINARY_DIR}/postinst;")
# Plugin dev
set(CPACK_COMPONENT_HDF5-PLUGIN-ECF-DEV_DESCRIPTION "HDF5 ECF Plugin (C++) files")
set(CPACK_DEBIAN_HDF5-PLUGIN-ECF-DEV_FILE_NAME "hdf5-plugin-ecf-dev-${PROJECT_VERSION}.deb")
set(CPACK_DEBIAN_HDF5-PLUGIN-ECF-DEV_PACKAGE_NAME "hdf5-plugin-ecf-dev")
set(CPACK_COMPONENT_HDF5-PLUGIN-ECF-DEV_DEPENDS hdf5-ecf-codec-dev)
include(CPack) # This has to be at the end