CMakeLists.txt 13.5 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)
87 88
    find_package(PythonInterp)
    find_package(PythonLibs)
89 90 91
    if(${PYTHONINTERP_FOUND})
      # python site-packages folder
      execute_process(
92 93 94 95 96
        COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print (get_python_lib())"
        OUTPUT_VARIABLE _PYTHON_SITE_PACKAGES_DIR
        OUTPUT_STRIP_TRAILING_WHITESPACE)
  	else()
  		message(FATAL_ERROR "No python found, please install or disable LIMA_ENABLE_PYTHON")
97 98 99 100
    endif()

    set(PYTHON_SITE_PACKAGES_DIR ${_PYTHON_SITE_PACKAGES_DIR} CACHE PATH "where should python modules be installed?")

101 102
    find_package(SIP REQUIRED)
    include(SIPMacros)
103
    if(WIN32)
104
      set(SIP_TAGS WIN32_PLATFORM)
105
    elseif(UNIX)
106
      set(SIP_TAGS POSIX_PLATFORM)
107
    endif(WIN32)
108
    set(SIP_EXTRA_OPTIONS -e -g)
109 110 111

    find_package(NumPy REQUIRED)
 endif()
112

113 114 115
#--------------------------------------------------------------------------------
# Define source files
#--------------------------------------------------------------------------------
116

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
# 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)
135

136 137 138 139 140
if(UNIX)
    list(APPEND common_srcs
        common/src/RegExUtils.cpp
        common/src/SimplePipe.cpp
    )
Yann Voté's avatar
Yann Voté committed
141 142
endif()

143 144
file(GLOB_RECURSE common_incs "common/include/*.h")

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
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
)
166

167 168
if(UNIX)
    list(APPEND hardware_srcs hardware/src/HwFileEventMgr.cpp)
Yann Voté's avatar
Yann Voté committed
169 170
endif()

171 172
file(GLOB_RECURSE hardware_incs "hardware/include/*.h")

173 174 175 176 177 178 179 180 181 182 183 184 185
set(control_srcs
    control/src/CtSaving.cpp
    control/src/CtControl.cpp
    control/src/CtAcquisition.cpp
    control/src/CtBuffer.cpp
    control/src/CtImage.cpp
    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
)
186

187 188
file(GLOB_RECURSE control_incs "control/include/*.h")

189 190 191 192 193
set(software_operation_srcs
    control/software_operation/src/SoftOpInternalMgr.cpp
    control/software_operation/src/SoftOpExternalMgr.cpp
    control/software_operation/src/SoftOpId.cpp
)
194

195
file(GLOB_RECURSE software_operation_incs "control/software_operation/include/*.h")
196

197 198 199
set(extra_libs)
set(extra_includes)
set(extra_definitions)
200

201 202 203 204 205 206 207 208 209
# Optional for libconfig++ support
if(LIMA_ENABLE_CONFIG)
    find_package(Libconfig)
    if(${CONFIG_FOUND})
        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})
210
    else()
211
        message(FATAL_ERROR "libconfig++ not found, set LIB_CONFIG path or disable LIMA_ENABLE_CONFIG")
212
    endif()
213 214
endif()

215 216 217 218
# 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)
219 220
endif()

221 222
# Option for extra saving formats edf.gz, edf.lz4, cbf, hdf5, tiff, fits
include(Saving.cmake)
223

224 225 226
#--------------------------------------------------------------------------------
# Add the library limacore definition
#--------------------------------------------------------------------------------
227
add_library(limacore SHARED
228
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/project_version.cc # Add version info
229
    ${common_srcs}
230
    ${hardware_srcs}
231
    ${control_srcs}
232
    ${software_operation_srcs}
233 234 235
    ${common_incs}
    ${hardware_incs}
    ${control_incs}
236
    ${software_operation_incs}
237
)
238

239 240
# Set version
set_target_properties(limacore PROPERTIES
Samuel Debionne's avatar
Samuel Debionne committed
241
    VERSION "${PROJECT_VERSION}"
242 243 244 245
    SOVERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")

# Generate export macros
generate_export_header(limacore)
246

247
target_include_directories(limacore PUBLIC
248 249 250 251 252 253 254 255 256 257 258 259 260
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common/include>"
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hardware/include>"
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/control/include>"
    "$<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()

261
if(UNIX AND LIMA_ENABLE_NUMA)
262
    target_compile_definitions(limacore PUBLIC LIMA_USE_NUMA)
263 264 265
    target_include_directories(limacore PRIVATE "${NUMA_INCLUDE_DIR}")
endif()

266
if(LIMA_ENABLE_SPS_IMAGE)
267
    target_compile_definitions(limacore PUBLIC WITH_SPS_IMAGE)
268 269
    target_include_directories(limacore PRIVATE "${CMAKE_SOURCE_DIR}/third-party/Sps/Include")
endif()
270

271
# Set LIMA_NO_DEBUG if the build type is not debug
272
target_compile_definitions(limacore PUBLIC $<$<NOT:$<CONFIG:DEBUG>>:LIMA_NO_DEBUG>)
273

274 275
# add all include paths coming from saving format options
target_include_directories(limacore PRIVATE ${extra_includes} ${saving_includes})
276

277
# add compiler definitions required by saving libraries
278 279 280
target_compile_definitions(limacore PUBLIC ${extra_definitions} ${saving_definitions})

# add libraries
281
target_link_libraries(limacore PUBLIC Threads::Threads)
282 283
target_link_libraries(limacore PUBLIC processlib ${saving_libs} ${extra_libs})
target_link_libraries(limacore PRIVATE ${saving_private_libs})
284

285 286 287
if(UNIX)
    target_compile_definitions(limacore PUBLIC -DHAS_INOTIFY)
    target_link_libraries(limacore PUBLIC "rt")
288 289 290
    if(LIMA_ENABLE_NUMA)
        target_link_libraries(limacore PUBLIC ${NUMA_LIBRARY})
    endif()
291 292
endif()

Yann Voté's avatar
Yann Voté committed
293
if(WIN32)
294
    target_compile_definitions(limacore PRIVATE LIMACORE_EXPORTS)
295
    set_target_properties(limacore PROPERTIES PREFIX "lib")
296
    set_target_properties(limacore PROPERTIES IMPORT_PREFIX "lib")
Yann Voté's avatar
Yann Voté committed
297
endif()
298

299 300 301
#--------------------------------------------------------------------------------
# SIP generates binding code for python
#--------------------------------------------------------------------------------
302
if(LIMA_ENABLE_PYTHON)
303
    set(INCLUDES)
304
    file(GLOB SIP_SOURCES
305 306 307 308 309 310 311 312
         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")
313
    foreach(SIP_SOURCES ${SIP_SOURCES})
314 315
        set(INCLUDES
"${INCLUDES}
316
%Include ${SIP_SOURCES}"
317
)
318
    endforeach()
319

320
    configure_file(sip/limacore.sip.in sip/limacore.sip)
321
    configure_file(sip/lima_init_numpy.cpp.in sip/core/limacore_init_numpy.cpp)
322 323
    list(APPEND LIMA_SIP_INCLUDE_DIRS
        "${CMAKE_CURRENT_BINARY_DIR}/sip"
324 325 326 327
        "${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")
328
    if (LIMA_BUILD_SUBMODULES)
329 330
      list(APPEND LIMA_SIP_INCLUDE_DIRS
          "${CMAKE_CURRENT_SOURCE_DIR}/sip")
331 332
      # This is required for LimaTools
      list(APPEND PROCESSLIB_SIP_INCLUDE_DIRS
333 334 335
          "${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/sip"
          "${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/tasks/sip")
    endif()
336 337 338
    set(SIP_INCLUDE_DIRS
        ${LIMA_SIP_INCLUDE_DIRS}
        ${PROCESSLIB_SIP_INCLUDE_DIRS})
339 340 341 342 343
    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)
344
    endif()
345
    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/sip/limacore.sip PROPERTIES OBJECT_DEPENDS ${SIP_SOURCES})
346
    # Run sip now !
347
    add_sip_python_module(limacore ${CMAKE_CURRENT_BINARY_DIR}/sip/limacore.sip FALSE)
348

349
    target_include_directories(python_module_limacore PRIVATE
350
        ${PYTHON_INCLUDE_DIRS}
351
        ${NUMPY_INCLUDE_DIRS}
352 353 354
        ${CMAKE_CURRENT_SOURCE_DIR}/sip
        ${CMAKE_CURRENT_SOURCE_DIR}/sip/core
        ${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/sip)
355
    target_link_libraries(python_module_limacore PRIVATE limacore ${NUMPY_LIBRARIES})
356

357
    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)
358 359
endif()

360 361 362 363
## Installation

include(Install.cmake)

364 365 366 367
#--------------------------------------------------------------------------------
# Option for openGL real-time display  support
#--------------------------------------------------------------------------------
if(LIMA_ENABLE_GLDISPLAY)
368
    add_subdirectory(third-party/gldisplay)
369 370
endif()

371
#--------------------------------------------------------------------------------
372
# TESTS, run ctest or make test
373
#--------------------------------------------------------------------------------
374 375
if(LIMA_ENABLE_TESTS)
    enable_testing()
376
    add_subdirectory(control/test)
377
    add_subdirectory(common/test)
378 379
endif()

380 381 382
#--------------------------------------------------------------------------------
# CAMERA list is in cmake/CameraList.cmake file
#--------------------------------------------------------------------------------
383 384 385
if (LIMA_BUILD_SUBMODULES)
    include(CameraList)
endif()
386

387 388 389 390 391 392 393
#--------------------------------------------------------------------------------
# Python Tango server
#--------------------------------------------------------------------------------
if(LIMA_ENABLE_PYTANGO_SERVER)
    add_subdirectory(applications/tango/python)
endif()

394 395 396
#--------------------------------------------------------------------------------
# PACKAGES debian at least, run cpack or make package
#--------------------------------------------------------------------------------
397 398 399 400
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ESRF/BLISS") #required
set(CPACK_PACKAGE_CONTACT "lima@esrf.fr")
include(CPack)