-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
201 lines (163 loc) · 5.33 KB
/
CMakeLists.txt
File metadata and controls
201 lines (163 loc) · 5.33 KB
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
#
# This is a file to be interpreted by cmake (https://cmake.org/)
# Please note that all dependencies have to be available first.
#
# To uninstall:
#
# sudo xargs --interactive rm < install_manifest.txt
#
# Please note that this will remove also the libraries that might be
# used by other programs.
cmake_minimum_required(VERSION 3.20)
project(nd2tool
DESCRIPTION "convert Nikon nd2 files to tif"
HOMEPAGE_URL "https://github.com/elgw/nd2tool/"
VERSION "0.1.8"
LANGUAGES C)
enable_language(C)
set (CMAKE_C_STANDARD 11)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
${CMAKE_CURRENT_SOURCE_DIR}/src/version.h)
option (ENABLE_NATIVE_OPTIMIZATION "Enable non-portable optimizations" OFF)
#
# Default build type is RELEASE
#
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
#
# Add source files
#
add_executable(nd2tool
src/main.c
src/nd2tool.c
src/tiff_util.c
src/json_util.c
src/srgb_from_lambda.c
src/nd2tool_util.c)
add_executable(nd2tool_recover EXCLUDE_FROM_ALL
src/recover_nd2.c)
#
# Add headers
#
target_include_directories(nd2tool PRIVATE include/)
find_package(Git)
set(ND2TOOL_GIT_VERSION "unknown")
if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --broken
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE ND2TOOL_GIT_VERSION
RESULT_VARIABLE ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
target_compile_definitions(nd2tool PUBLIC "ND2TOOL_GIT_VERSION=\"${ND2TOOL_GIT_VERSION}\"")
#
# Add Nikon's library
#
if (UNIX)
if (APPLE)
message(STATUS "Linking against .dylib")
#target_link_libraries(nd2tool "${CMAKE_SOURCE_DIR}/lib/libnd2readsdk-shared.dylib")
make_directory(lib)
add_custom_command(TARGET nd2tool POST_BUILD # Adds a post-build event to MyTest
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
"${PROJECT_SOURCE_DIR}/lib/nd2readsdk-shared-1.7.6.0-Macos-armv8/*.dylib" # <--this is in-file
"$<TARGET_FILE_DIR:nd2tool>/lib") # <--this is out-file path
target_link_libraries(nd2tool "libnd2readsdk-shared.dylib")
else()
message(STATUS "Linking against so files")
target_link_libraries(nd2tool "${CMAKE_SOURCE_DIR}/lib/liblimfile-shared.so")
target_link_libraries(nd2tool "${CMAKE_SOURCE_DIR}/lib/libnd2readsdk-shared.so")
# Copy it to the build dir upon compilation
add_custom_command(TARGET nd2tool POST_BUILD # Adds a post-build event to MyTest
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
"${PROJECT_SOURCE_DIR}/lib/*.so" # <--this is in-file
$<TARGET_FILE_DIR:nd2tool>) # <--this is out-file path
endif ()
endif ()
#
# Link time optimization
#
# https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
message("Enabling IPO")
set_property(TARGET nd2tool PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_JOBS 8)
else()
message(WARNING "IPO is not supported: ${output}")
endif()
#
# Architecture optimizations
#
if(ENABLE_NATIVE_OPTIMIZATION)
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
endif()
CHECK_C_COMPILER_FLAG("-mtune=native" COMPILER_SUPPORTS_MTUNE_NATIVE)
if(COMPILER_SUPPORTS_MTUNE_NATIVE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native")
endif()
endif()
#
# Math library, if needed
#
find_library(MATH_LIBRARY m)
if(MATH_LIBRARY)
target_link_libraries(nd2tool ${MATH_LIBRARY})
endif()
#
# TIFF
#
find_package(TIFF REQUIRED)
target_include_directories(nd2tool PRIVATE ${TIFF_INCLUDE_DIRS})
target_link_libraries(nd2tool ${TIFF_LIBRARIES})
# On Ubuntu 24, first get libtiff.so.5 into the library
# path, then use this line instead:
#target_link_libraries(nd2tool -l:libtiff.so.5)
#
# cJSON
#
# Not sure if this works on macos because of a more recent version
# of cmake or because the homebrew package contains some extra files
if(APPLE)
find_package(cjson REQUIRED)
endif()
target_link_libraries(nd2tool cjson)
# Enable -flto (GCC) and similar if available, see
# https://cmake.org/cmake/help/latest/policy/CMP0069.html
check_ipo_supported(RESULT result)
if(result)
message("Enabling IPO")
set_property(DIRECTORY PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
include(GNUInstallDirs)
install(TARGETS nd2tool)
install(FILES "${CMAKE_SOURCE_DIR}/doc/nd2tool.1"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1/" )
if (UNIX)
if (APPLE)
install(FILES
"${CMAKE_SOURCE_DIR}/lib/libnd2readsdk-shared.dylib"
"${CMAKE_SOURCE_DIR}/lib/liblimfile-shared.dylib"
TYPE LIB )
else()
install(FILES
"${CMAKE_SOURCE_DIR}/lib/liblimfile-shared.so"
"${CMAKE_SOURCE_DIR}/lib/libnd2readsdk-shared.so"
TYPE LIB )
endif()
endif()
# https://cmake.org/cmake/help/book/mastering-cmake/chapter/Packaging%20With%20CPack.html
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "ELGW") #required
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) # resolve dependencies automatically
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://www.github.com/elgw/nd2tool/")
INCLUDE(CPack)