CMakeLists.txt 12.9 KB
Newer Older
1
2
3
4
5
6
7
###########################################################################
# This file is part of LImA, a Library for Image Acquisition
#
#  Copyright (C) : 2009-2017
#  European Synchrotron Radiation Facility
#  BP 220, Grenoble 38043
#  FRANCE
8
#
9
#  Contact: lima@esrf.fr
10
#
11
12
13
14
#  This is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
15
#
16
17
18
19
#  This software is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
20
#
21
22
23
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, see <http://www.gnu.org/licenses/>.
############################################################################
24

25
cmake_minimum_required(VERSION 3.1)
26

27
project (Lima)
28
include(cmake/project_version.cmake)
29

30
31
set(NAME "core")

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Include additional modules that are used unconditionally
include(GNUInstallDirs)
include(GenerateExportHeader)

# If conda build, always set lib dir to 'lib'
if($ENV{CONDA_BUILD})
  set(CMAKE_INSTALL_LIBDIR "lib")
endif()

# Set lower / upper case project names
string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER)
string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER)

# Set targets export name (used by lima and dependencies)
set(TARGETS_EXPORT_NAME "${PROJECT_NAME_LOWER}-targets")
#set(namespace "${PROJECT_NAME}::")

49
50
51
52
# Enable C++11 and later
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

53
if(MSVC AND MSVC_VERSION GREATER 1500)
54
55
56
    # Compiler specific (parallel build)
    set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} /MP")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
57
endif()
58

59
# CMake additional macros
Samuel Debionne's avatar
Samuel Debionne committed
60
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
61
include(LimaTools)
62

63
64
65
66
67
if(UNIX AND LIMA_ENABLE_NUMA)
    # Numa is needed for advanced buffer management
    find_package(Numa REQUIRED)
endif()

68
69
# Import pthread
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
70
find_package(Threads REQUIRED)
71

72
### Define options
73

74
include(Options.cmake)
75

76
### Find dependencies
77

78
79
80
# Processlib third-party is mandatory
if (LIMA_BUILD_SUBMODULES)
    add_subdirectory(third-party/Processlib)
81
else()
82
    find_package(Processlib REQUIRED)
83
84
endif()

85
86
# Enable python binding code compilation using sip generator
if(LIMA_ENABLE_PYTHON)
Laurent Claustre's avatar
Laurent Claustre committed
87
  limatools_find_python_and_sip()
88
endif()
89

90
91
92
#--------------------------------------------------------------------------------
# Define source files
#--------------------------------------------------------------------------------
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# add_subdirectory(common)
# add_subdirectory(control)
# add_subdirectory(control/software_operation)
# add_subdirectory(hardware)

set(common_srcs
    common/src/Constants.cpp
    common/src/SizeUtils.cpp
    common/src/Timestamp.cpp
    common/src/ThreadUtils.cpp
    common/src/Exceptions.cpp
    common/src/MemUtils.cpp
    common/src/AcqState.cpp
    common/src/Debug.cpp
    common/src/VideoUtils.cpp
    common/src/Event.cpp
    common/src/Timer.cpp
    common/src/DirectoryEventUtils.cpp)
112

113
114
115
116
117
if(UNIX)
    list(APPEND common_srcs
        common/src/RegExUtils.cpp
        common/src/SimplePipe.cpp
    )
Yann Voté's avatar
Yann Voté committed
118
119
endif()

120
121
file(GLOB_RECURSE common_incs "common/include/*.h")

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
set(hardware_srcs
    hardware/src/HwInterface.cpp
    hardware/src/HwCap.cpp
    hardware/src/HwSyncCtrlObj.cpp
    hardware/src/HwFrameInfo.cpp
    hardware/src/HwFrameCallback.cpp
    hardware/src/HwBufferCtrlObj.cpp
    hardware/src/HwBufferMgr.cpp
    hardware/src/HwShutterCtrlObj.cpp
    hardware/src/HwMaxImageSizeCallback.cpp
    hardware/src/HwDetInfoCtrlObj.cpp
    hardware/src/HwBinCtrlObj.cpp
    hardware/src/HwRoiCtrlObj.cpp
    hardware/src/HwFlipCtrlObj.cpp
    hardware/src/HwSerialLine.cpp
    hardware/src/HwBufferSave.cpp
    hardware/src/HwVideoCtrlObj.cpp
    hardware/src/HwEventCtrlObj.cpp
    hardware/src/HwSavingCtrlObj.cpp
    hardware/src/HwReconstructionCtrlObj.cpp
)
143

144
145
if(UNIX)
    list(APPEND hardware_srcs hardware/src/HwFileEventMgr.cpp)
Yann Voté's avatar
Yann Voté committed
146
147
endif()

148
149
file(GLOB_RECURSE hardware_incs "hardware/include/*.h")

150
151
152
153
154
155
set(control_srcs
    control/src/CtSaving.cpp
    control/src/CtControl.cpp
    control/src/CtAcquisition.cpp
    control/src/CtBuffer.cpp
    control/src/CtImage.cpp
156
    control/src/CtSaving_ZBuffer.cpp
157
158
159
160
161
162
163
    control/src/CtSaving_Compression.cpp
    control/src/CtSaving_Edf.cpp
    control/src/CtShutter.cpp
    control/src/CtAccumulation.cpp
    control/src/CtVideo.cpp
    control/src/CtEvent.cpp
)
164

165
166
file(GLOB_RECURSE control_incs "control/include/*.h")

167
168
169
170
171
set(software_operation_srcs
    control/software_operation/src/SoftOpInternalMgr.cpp
    control/software_operation/src/SoftOpExternalMgr.cpp
    control/software_operation/src/SoftOpId.cpp
)
172

173
file(GLOB_RECURSE software_operation_incs "control/software_operation/include/*.h")
174

175
176
177
set(extra_libs)
set(extra_includes)
set(extra_definitions)
178

179
180
181
# Optional for libconfig++ support
if(LIMA_ENABLE_CONFIG)
    find_package(Libconfig)
182
    if(${LIBCONFIG_FOUND})
183
184
185
186
187
        list(APPEND extra_definitions -DWITH_CONFIG)
        list(APPEND extra_libs ${LIBCONFIG_LIBRARIES})
        list(APPEND common_srcs common/src/ConfigUtils.cpp)
        list(APPEND control_srcs control/src/CtConfig.cpp)
        list(APPEND extra_includes ${LIBCONFIG_INCLUDE_DIRS})
188
    else()
189
        message(FATAL_ERROR "libconfig++ not found, set LIB_CONFIG path or disable LIMA_ENABLE_CONFIG")
190
    endif()
191
192
endif()

193
194
195
196
# Option for Spec-like shared-memory (SPS)  support
if(LIMA_ENABLE_SPS_IMAGE)
    list(APPEND extra_definitions -DWITH_SPS_IMAGE)
    list(APPEND control_srcs control/src/CtSpsImage.cpp third-party/Sps/Src/sps.c)
197
198
endif()

199
200
# Option for extra saving formats edf.gz, edf.lz4, cbf, hdf5, tiff, fits
include(Saving.cmake)
201

202
203
204
#--------------------------------------------------------------------------------
# Add the library limacore definition
#--------------------------------------------------------------------------------
205
add_library(limacore SHARED
206
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_LOWER}/project_version.cc # Add version info
207
    ${common_srcs}
208
    ${hardware_srcs}
209
    ${control_srcs}
210
    ${software_operation_srcs}
211
212
213
    ${common_incs}
    ${hardware_incs}
    ${control_incs}
214
    ${software_operation_incs}
215
)
216

217
218
# Set version
set_target_properties(limacore PROPERTIES
Samuel Debionne's avatar
Samuel Debionne committed
219
    VERSION "${PROJECT_VERSION}"
220
221
222
223
    SOVERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")

# Generate export macros
generate_export_header(limacore)
Laurent Claustre's avatar
Laurent Claustre committed
224
225
226
message("#####################################")
message("${CMAKE_BINARY_DIR}")
message("#####################################")
227

228
target_include_directories(limacore PUBLIC
229
230
231
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common/include>"
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hardware/include>"
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/control/include>"
Laurent Claustre's avatar
Laurent Claustre committed
232
    "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>"
233
234
235
236
237
238
239
240
241
242
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/control/software_operation/include>"
    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

if(LIMA_BUILD_SUBMODULES)
    target_include_directories(limacore PUBLIC
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/core/include>"
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/tasks/include>")
endif()

243
if(UNIX AND LIMA_ENABLE_NUMA)
244
    target_compile_definitions(limacore PUBLIC LIMA_USE_NUMA)
245
246
247
    target_include_directories(limacore PRIVATE "${NUMA_INCLUDE_DIR}")
endif()

248
if(LIMA_ENABLE_SPS_IMAGE)
249
    target_compile_definitions(limacore PUBLIC WITH_SPS_IMAGE)
250
251
    target_include_directories(limacore PRIVATE "${CMAKE_SOURCE_DIR}/third-party/Sps/Include")
endif()
252

Samuel Debionne's avatar
Samuel Debionne committed
253
254
255
256
# Set LIMA_NO_DEBUG if LIMA_ENABLE_DEBUG is set
if(NOT LIMA_ENABLE_DEBUG)
    target_compile_definitions(limacore PUBLIC LIMA_NO_DEBUG)
endif()
257

258
259
# add all include paths coming from saving format options
target_include_directories(limacore PRIVATE ${extra_includes} ${saving_includes})
260

261
# add compiler definitions required by saving libraries
262
263
264
target_compile_definitions(limacore PUBLIC ${extra_definitions} ${saving_definitions})

# add libraries
265
target_link_libraries(limacore PUBLIC Threads::Threads)
266
267
target_link_libraries(limacore PUBLIC processlib ${saving_libs} ${extra_libs})
target_link_libraries(limacore PRIVATE ${saving_private_libs})
268

269
270
271
if(UNIX)
    target_compile_definitions(limacore PUBLIC -DHAS_INOTIFY)
    target_link_libraries(limacore PUBLIC "rt")
272
273
274
    if(LIMA_ENABLE_NUMA)
        target_link_libraries(limacore PUBLIC ${NUMA_LIBRARY})
    endif()
275
276
endif()

Yann Voté's avatar
Yann Voté committed
277
if(WIN32)
278
    target_compile_definitions(limacore PRIVATE LIMACORE_EXPORTS)
279
    set_target_properties(limacore PROPERTIES PREFIX "lib")
280
    set_target_properties(limacore PROPERTIES IMPORT_PREFIX "lib")
Yann Voté's avatar
Yann Voté committed
281
endif()
282

283
284
285
#--------------------------------------------------------------------------------
# SIP generates binding code for python
#--------------------------------------------------------------------------------
286
if(LIMA_ENABLE_PYTHON)
287
    set(INCLUDES)
288
    file(GLOB SIP_SOURCES
289
290
291
292
293
294
295
296
         RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/common/sip"
         "${CMAKE_CURRENT_SOURCE_DIR}/common/sip/*.sip"
         RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/hardware/sip"
         "${CMAKE_CURRENT_SOURCE_DIR}/hardware/sip/*.sip"
         RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/control/sip"
         "${CMAKE_CURRENT_SOURCE_DIR}/control/sip/*.sip"
         RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/control/software_operation/sip"
         "${CMAKE_CURRENT_SOURCE_DIR}/control/software_operation/sip/*.sip")
297
    foreach(SIP_SOURCES ${SIP_SOURCES})
298
299
        set(INCLUDES
"${INCLUDES}
300
%Include ${SIP_SOURCES}"
301
)
302
    endforeach()
303

304
    configure_file(sip/limacore.sip.in sip/limacore.sip)
305
306
    list(APPEND LIMA_SIP_INCLUDE_DIRS
        "${CMAKE_CURRENT_BINARY_DIR}/sip"
307
308
309
310
        "${CMAKE_CURRENT_SOURCE_DIR}/common/sip"
        "${CMAKE_CURRENT_SOURCE_DIR}/hardware/sip"
        "${CMAKE_CURRENT_SOURCE_DIR}/control/sip"
        "${CMAKE_CURRENT_SOURCE_DIR}/control/software_operation/sip")
311
    if (LIMA_BUILD_SUBMODULES)
312
313
      list(APPEND LIMA_SIP_INCLUDE_DIRS
          "${CMAKE_CURRENT_SOURCE_DIR}/sip")
314
315
      # This is required for LimaTools
      list(APPEND PROCESSLIB_SIP_INCLUDE_DIRS
316
317
318
          "${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/sip"
          "${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/tasks/sip")
    endif()
319
320
321
    set(SIP_INCLUDE_DIRS
        ${LIMA_SIP_INCLUDE_DIRS}
        ${PROCESSLIB_SIP_INCLUDE_DIRS})
322
323
324
325
326
    if (NOT LIMA_ENABLE_CONFIG)
      set(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} WITH_CONFIG)
    endif()
    if (NOT LIMA_ENABLE_SPS_IMAGE)
      set(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} WITH_SPS_IMAGE)
327
    endif()
328
    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/sip/limacore.sip PROPERTIES OBJECT_DEPENDS ${SIP_SOURCES})
329
    # Run sip now !
330
    add_sip_python_module(limacore ${CMAKE_CURRENT_BINARY_DIR}/sip/limacore.sip FALSE)
331

332
    target_include_directories(python_module_limacore PRIVATE
333
        ${PYTHON_INCLUDE_DIRS}
334
        ${NUMPY_INCLUDE_DIRS}
335
336
337
        ${CMAKE_CURRENT_SOURCE_DIR}/sip
        ${CMAKE_CURRENT_SOURCE_DIR}/sip/core
        ${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/sip)
338
    target_link_libraries(python_module_limacore PRIVATE limacore ${NUMPY_LIBRARIES})
339

340
    add_custom_command(TARGET lima${NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/python/Lima ${CMAKE_BINARY_DIR}/python/Lima)
341
342
endif()

343
344
345
346
## Installation

include(Install.cmake)

347
348
349
350
#--------------------------------------------------------------------------------
# Option for openGL real-time display  support
#--------------------------------------------------------------------------------
if(LIMA_ENABLE_GLDISPLAY)
351
    add_subdirectory(third-party/gldisplay)
352
353
endif()

354
#--------------------------------------------------------------------------------
355
# TESTS, run ctest or make test
356
#--------------------------------------------------------------------------------
357
358
if(LIMA_ENABLE_TESTS)
    enable_testing()
359
    add_subdirectory(control/test)
360
    add_subdirectory(common/test)
361
362
endif()

363
364
365
#--------------------------------------------------------------------------------
# CAMERA list is in cmake/CameraList.cmake file
#--------------------------------------------------------------------------------
366
367
368
if (LIMA_BUILD_SUBMODULES)
    include(CameraList)
endif()
369

370
371
372
373
374
375
376
#--------------------------------------------------------------------------------
# Python Tango server
#--------------------------------------------------------------------------------
if(LIMA_ENABLE_PYTANGO_SERVER)
    add_subdirectory(applications/tango/python)
endif()

377
378
379
#--------------------------------------------------------------------------------
# PACKAGES debian at least, run cpack or make package
#--------------------------------------------------------------------------------
380
381
382
383
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ESRF/BLISS") #required
set(CPACK_PACKAGE_CONTACT "lima@esrf.fr")
include(CPack)