CMakeLists.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. # CBSDK CMake Build System
  2. # Author: griffin.milsap@gmail.com
  3. # chadwick.boulay@gmail.com
  4. # Version 1.1 Jan. 2017
  5. # Build information for
  6. # cbsdk Library
  7. # -shared, -static (optional), -matlab (optional), -octave (optional)
  8. # -testcbsdk Test Binary (optional)
  9. # See "Optional Targets" below for options to disable specific targets.
  10. #
  11. # MATLAB:
  12. # First ../Matlab is looked.
  13. # If mex.h is not found then FindMatlab.cmake looks at usual places.
  14. # Use -DMatlab_ROOT_DIR if installed in unknown location (or copy to ../Matlab).
  15. # e.g., Matlab R2016a on Mac OS: -DMatlab_ROOT_DIR=/Applications/MATLAB_R2016a.app/
  16. # -DCBMEX_INSTALL_PREFIX can be used to install cbmex to given directory
  17. #
  18. # QT:
  19. # QT5 ships with its own cmake config files. We need to tell CMake where to find this.
  20. # On Mac OS, assuming qt installed with homebrew,
  21. # run CMake with -DCMAKE_PREFIX_PATH=$(brew --prefix qt5)
  22. # On Windows, run CMake with -DQt5_DIR=path\to\qt\version\platform\lib\cmake\Qt5
  23. # For example: cmake .. -G "Visual Studio 14 2015 Win64" -DQt5_DIR=C:\Qt\5.9.1\msvc2015_64\lib\cmake\Qt5
  24. CMAKE_MINIMUM_REQUIRED( VERSION 3.1.0 )
  25. PROJECT( CBSDK VERSION 1.0.2 )
  26. SET( CBSDK_VERSION_MAJOR 1 )
  27. SET( CBSDK_VERSION_MINOR 0 )
  28. ##########################################################################################
  29. # Optional Targets
  30. option(BUILD_STATIC "Build static cbsdk library" ON)
  31. option(BUILD_CBMEX "Build Matlab wrapper" ON)
  32. option(BUILD_CBOCT "Build Octave wrapper" ON)
  33. option(BUILD_TEST "Build testcbsdk" ON)
  34. option(BUILD_HDF5 "Build HDF5" ON)
  35. ##########################################################################################
  36. # Define target names
  37. SET( LIB_NAME cbsdk )
  38. SET( INSTALL_TARGET_LIST ${LIB_NAME} )
  39. SET( LIB_NAME_STATIC cbsdk_static )
  40. SET( LIB_NAME_CBMEX cbmex )
  41. SET( LIB_NAME_CBOCT cboct )
  42. SET( TEST_NAME testcbsdk )
  43. SET( N2H5_NAME n2h5 )
  44. ##########################################################################################
  45. # Store some platform-specific strings used to construct lib names / folder structures.
  46. IF ( WIN32 )
  47. SET( PLATFORM_NAME "win" )
  48. ELSEIF ( APPLE )
  49. SET( PLATFORM_NAME "osx" )
  50. ELSE ( WIN32 )
  51. SET( PLATFORM_NAME "linux" )
  52. ENDIF ( WIN32 )
  53. # Handle 64 bit binaries
  54. IF( CMAKE_SIZEOF_VOID_P EQUAL 4 )
  55. SET( LIB_SUFFIX "" )
  56. SET( PLATFORM_NAME ${PLATFORM_NAME}32 )
  57. ELSE( CMAKE_SIZEOF_VOID_P EQUAL 4 )
  58. SET( LIB_SUFFIX 64 )
  59. SET( PLATFORM_NAME ${PLATFORM_NAME}64 )
  60. ENDIF( CMAKE_SIZEOF_VOID_P EQUAL 4 )
  61. IF( ${PLATFORM_NAME} STREQUAL osx64 )
  62. SET( LIB_SUFFIX "" )
  63. ENDIF( ${PLATFORM_NAME} STREQUAL osx64 )
  64. ##########################################################################################
  65. # Misc Configuration
  66. # Introduce variables:
  67. # * CMAKE_INSTALL_LIBDIR
  68. # * CMAKE_INSTALL_BINDIR
  69. # * CMAKE_INSTALL_INCLUDEDIR
  70. include(GNUInstallDirs)
  71. # This determines how dynamic libraries are found at runtime
  72. if(IOS)
  73. # TODO
  74. elseif(ANDROID)
  75. # TODO
  76. elseif(UNIX)
  77. if(APPLE)
  78. set(CMAKE_INSTALL_RPATH "@executable_path/../${CMAKE_INSTALL_LIBDIR}")
  79. else()
  80. set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
  81. endif()
  82. endif()
  83. # -Make sure debug builds are recognized
  84. SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Add a postfix, usually d on windows")
  85. # -Find additional cmake modules
  86. SET( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} )
  87. LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
  88. # -?
  89. ADD_DEFINITIONS( -DCBSDK_EXPORTS )
  90. IF( WIN32 )
  91. # From cbhwlib/cbmex.vcproj: PreprocessorDefinitions="WIN32;_WINDOWS;NO_AFX;WINVER=0x0501;CBSDK_EXPORTS;QT_APP"
  92. ADD_DEFINITIONS( -DWIN32 -D_WINDOWS -DNO_AFX -DWINVER=0x0501 -DNOMINMAX
  93. -D_CRT_SECURE_NO_WARNINGS
  94. -D_WINSOCK_DEPRECATED_NO_WARNINGS) # Not necessary if -DUNICODE
  95. ENDIF( WIN32 )
  96. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  97. cmake_policy(SET CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types.
  98. cmake_policy(SET CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default.
  99. ##########################################################################################
  100. # Third party libraries
  101. # -Qt
  102. #We could use a variable to make this editable by GUI, but then we have to clear Qt4 variables for reconfigure.
  103. #SET(CMAKE_PREFIX_PATH "." CACHE PATH "Qt path. e.g., C:\\Qt\\5.8\\msvc2015_64\\")
  104. SET(USING_QT5 OFF)
  105. find_package(Qt5 COMPONENTS Core)
  106. IF(Qt5_FOUND)
  107. MESSAGE(STATUS "Found Qt ${Qt5Core_VERSION_STRING}")
  108. SET(USING_QT5 ON)
  109. FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Xml Concurrent)
  110. ELSE(Qt5_FOUND)
  111. FIND_PACKAGE( Qt4 REQUIRED QtCore QtXml)
  112. ENDIF(Qt5_FOUND)
  113. IF(${USING_QT5})
  114. SET(QT_LIBRARIES Qt5::Core Qt5::Xml Qt5::Concurrent)
  115. ELSE(${USING_QT5})
  116. INCLUDE( ${QT_USE_FILE} )
  117. ENDIF(${USING_QT5})
  118. ADD_DEFINITIONS( ${QT_DEFINITIONS} -DQT_APP )
  119. # -HDF5
  120. IF(${BUILD_HDF5})
  121. FIND_PACKAGE( HDF5 COMPONENTS C HL)
  122. ENDIF()
  123. # -Matlab
  124. IF(${BUILD_CBMEX})
  125. # Try MATLAB locally first, then on MATLAB install
  126. SET( MATLAB_FOUND NO)
  127. FIND_PATH( Matlab_INCLUDE_DIRS
  128. "mex.h"
  129. "${PROJECT_SOURCE_DIR}/Matlab/include"
  130. )
  131. IF ( Matlab_INCLUDE_DIRS )
  132. message(STATUS "Matlab_INCLUDE_DIRS ${Matlab_INCLUDE_DIRS}")
  133. SET( MATLAB_ROOT "${PROJECT_SOURCE_DIR}/Matlab" )
  134. MESSAGE ( STATUS "Search mex libraries at " ${Matlab_INCLUDE_DIRS}/../lib/${PLATFORM_NAME} )
  135. FILE( GLOB_RECURSE Matlab_LIBRARIES ${Matlab_INCLUDE_DIRS}/../lib/${PLATFORM_NAME}/libm*.* )
  136. IF( Matlab_LIBRARIES )
  137. SET( MATLAB_FOUND TRUE)
  138. ENDIF( Matlab_LIBRARIES )
  139. ENDIF ( Matlab_INCLUDE_DIRS )
  140. IF (NOT MATLAB_FOUND)
  141. #SET( MATLAB_FIND_DEBUG 1 )
  142. FIND_PACKAGE( Matlab COMPONENTS MX_LIBRARY)
  143. ENDIF ( NOT MATLAB_FOUND )
  144. ENDIF()
  145. # -Octave
  146. IF(${BUILD_CBOCT})
  147. FIND_PACKAGE( Octave )
  148. ENDIF()
  149. ##########################################################################################
  150. # Files/folders common to multiple targets
  151. SET( LIB_INCL_DIRS
  152. ${PROJECT_SOURCE_DIR}/cbhwlib
  153. ${PROJECT_SOURCE_DIR}/Central
  154. ${PROJECT_SOURCE_DIR}/CentralCommon
  155. )
  156. IF( WIN32 )
  157. LIST(APPEND LIB_INCL_DIRS "${PROJECT_SOURCE_DIR}/compat/")
  158. ENDIF( WIN32 )
  159. SET( LIB_SOURCE
  160. ${PROJECT_SOURCE_DIR}/cbmex/cbsdk.cpp
  161. ${PROJECT_SOURCE_DIR}/cbmex/cbsdk.h
  162. ${PROJECT_SOURCE_DIR}/cbmex/SdkApp.h
  163. ${PROJECT_SOURCE_DIR}/cbhwlib/cbhwlib.cpp
  164. ${PROJECT_SOURCE_DIR}/cbhwlib/cbhwlib.h
  165. ${PROJECT_SOURCE_DIR}/cbhwlib/cbHwlibHi.cpp
  166. ${PROJECT_SOURCE_DIR}/cbhwlib/cbHwlibHi.h
  167. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtils.cpp
  168. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtils.h
  169. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtilsBinary.cpp
  170. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtilsBinary.h
  171. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtilsConcurrent.cpp
  172. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtilsConcurrent.h
  173. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtilsXml.cpp
  174. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtilsXml.h
  175. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtilsXmlItems.cpp
  176. ${PROJECT_SOURCE_DIR}/cbhwlib/CCFUtilsXmlItems.h
  177. ${PROJECT_SOURCE_DIR}/cbhwlib/InstNetwork.cpp
  178. ${PROJECT_SOURCE_DIR}/cbhwlib/InstNetwork.h
  179. ${PROJECT_SOURCE_DIR}/cbhwlib/XmlFile.cpp
  180. ${PROJECT_SOURCE_DIR}/cbhwlib/XmlFile.h
  181. ${PROJECT_SOURCE_DIR}/Central/Instrument.cpp
  182. ${PROJECT_SOURCE_DIR}/Central/Instrument.h
  183. ${PROJECT_SOURCE_DIR}/Central/UDPsocket.cpp
  184. ${PROJECT_SOURCE_DIR}/Central/UDPsocket.h
  185. )
  186. IF( WIN32 )
  187. LIST ( APPEND LIB_SOURCE ${PROJECT_SOURCE_DIR}/cbmex/cbMex.rc ) # ??
  188. ENDIF( WIN32 )
  189. # Qt-MOC headers that need it
  190. SET( LIB_HEADERS
  191. ${PROJECT_SOURCE_DIR}/cbhwlib/InstNetwork.h
  192. )
  193. IF(${USING_QT5})
  194. QT5_WRAP_CPP( LIB_HEADERS_MOC ${LIB_HEADERS} )
  195. ELSE(${USING_QT5})
  196. QT4_WRAP_CPP( LIB_HEADERS_MOC ${LIB_HEADERS} )
  197. ENDIF(${USING_QT5})
  198. # Source for both cbmex and octave targets
  199. SET( LIB_SOURCE_CBMEX
  200. ${PROJECT_SOURCE_DIR}/cbmex/cbmex.cpp
  201. )
  202. ##########################################################################################
  203. # Targets
  204. ##
  205. # cbsdk shared / dynamic
  206. ADD_LIBRARY( ${LIB_NAME} SHARED ${LIB_SOURCE} ${LIB_HEADERS_MOC} )
  207. IF (NOT WIN32)
  208. # Hide unexported symbols
  209. IF( NOT APPLE )
  210. SET_TARGET_PROPERTIES( ${LIB_NAME} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL" )
  211. ENDIF( NOT APPLE )
  212. ENDIF(NOT WIN32)
  213. TARGET_INCLUDE_DIRECTORIES( ${LIB_NAME} PRIVATE "$<BUILD_INTERFACE:${LIB_INCL_DIRS}>")
  214. target_compile_definitions(${LIB_NAME} PUBLIC "${LIB_NAME}_DEBUG=$<CONFIG:Debug>")
  215. TARGET_LINK_LIBRARIES( ${LIB_NAME} ${QT_LIBRARIES} )
  216. IF( WIN32 )
  217. # From cbhw/cbmex.vcproj: AdditionalDependencies="ws2_32.lib winmm.lib libmx.lib libmex.lib libmat.lib QtXmlx644.lib QtCorex644.lib"
  218. TARGET_LINK_LIBRARIES( ${LIB_NAME} ws2_32 winmm )
  219. ENDIF( WIN32 )
  220. ##
  221. # cbsdk_static (optional)
  222. IF(${BUILD_STATIC})
  223. ADD_LIBRARY( ${LIB_NAME_STATIC} STATIC ${LIB_SOURCE} ${LIB_HEADERS_MOC} )
  224. TARGET_INCLUDE_DIRECTORIES( ${LIB_NAME_STATIC} PRIVATE "$<BUILD_INTERFACE:${LIB_INCL_DIRS}>")
  225. TARGET_LINK_LIBRARIES( ${LIB_NAME_STATIC} ${QT_LIBRARIES} )
  226. IF (WIN32 )
  227. TARGET_LINK_LIBRARIES( ${LIB_NAME_STATIC} ws2_32 winmm )
  228. ENDIF( WIN32 )
  229. IF( WIN32 )
  230. SET_TARGET_PROPERTIES( ${LIB_NAME_STATIC} PROPERTIES COMPILE_FLAGS "-DSTATIC_CBSDK_LINK")
  231. ELSE( WIN32 )
  232. # Need relocatable static library
  233. SET_TARGET_PROPERTIES( ${LIB_NAME_STATIC} PROPERTIES COMPILE_FLAGS "-fPIC") #-DSTATIC_CBSDK_LINK
  234. SET_TARGET_PROPERTIES( ${LIB_NAME_STATIC} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL" )
  235. #SET_TARGET_PROPERTIES(${LIB_NAME_STATIC} PROPERTIES XCODE_ATTRIBUTE_GENERATE_MASTER_OBJECT_FILE "YES")
  236. #SET_TARGET_PROPERTIES(${LIB_NAME_STATIC} PROPERTIES XCODE_ATTRIBUTE_STRIP_STYLE "non-global")
  237. #SET_TARGET_PROPERTIES(${LIB_NAME_STATIC} PROPERTIES XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES")
  238. #SET_TARGET_PROPERTIES(${LIB_NAME_STATIC} PROPERTIES XCODE_ATTRIBUTE_SEPARATE_STRIP "YES")
  239. ENDIF( WIN32)
  240. LIST(APPEND INSTALL_TARGET_LIST ${LIB_NAME_STATIC})
  241. ENDIF(${BUILD_STATIC})
  242. ##
  243. # cbmex
  244. IF(${BUILD_CBMEX} AND MATLAB_FOUND )
  245. MESSAGE ( STATUS "Add cbmex build target using MATLAB libs at " ${Matlab_ROOT_DIR})
  246. IF( WIN32 )
  247. SET ( LIB_SOURCE_CBMEX ${LIB_SOURCE_CBMEX} ${PROJECT_SOURCE_DIR}/cbmex/cbMex.rc )
  248. ENDIF( WIN32 )
  249. ADD_LIBRARY( ${LIB_NAME_CBMEX} SHARED ${LIB_SOURCE_CBMEX} )
  250. # Want package name to be cbmex without prefix
  251. IF( WIN32 )
  252. # Do not output to Debug/Release directories on Windows
  253. SET_TARGET_PROPERTIES( ${LIB_NAME_CBMEX} PROPERTIES PREFIX "../" )
  254. # Manually export mexFunction because __declspec(dllexport) conflicts with its definition in mex.h
  255. SET_TARGET_PROPERTIES( ${LIB_NAME_CBMEX} PROPERTIES LINK_FLAGS "/EXPORT:mexFunction" )
  256. ELSEIF( APPLE )
  257. SET_TARGET_PROPERTIES( ${LIB_NAME_CBMEX} PROPERTIES PREFIX "" )
  258. # This is for normal users of MATLAB on OSX without homebrew
  259. # so we try to use relative paths to be able to bundle shared libraries
  260. SET_TARGET_PROPERTIES( ${LIB_NAME_CBMEX} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@rpath")
  261. ELSE( WIN32 )
  262. SET_TARGET_PROPERTIES( ${LIB_NAME_CBMEX} PROPERTIES PREFIX "" )
  263. SET_TARGET_PROPERTIES( ${LIB_NAME_CBMEX} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL" )
  264. ENDIF( WIN32 )
  265. SET_TARGET_PROPERTIES( ${LIB_NAME_CBMEX} PROPERTIES SUFFIX .${Matlab_MEX_EXTENSION})
  266. IF( NOT CBMEX_INSTALL_PREFIX )
  267. SET( CBMEX_INSTALL_PREFIX .)
  268. ENDIF( NOT CBMEX_INSTALL_PREFIX )
  269. # Use static library to build cbmex
  270. ADD_DEPENDENCIES( ${LIB_NAME_CBMEX} ${LIB_NAME_STATIC} )
  271. TARGET_INCLUDE_DIRECTORIES( ${LIB_NAME_CBMEX}
  272. PRIVATE "$<BUILD_INTERFACE:${LIB_INCL_DIRS}>" ${Matlab_INCLUDE_DIRS}
  273. )
  274. TARGET_LINK_LIBRARIES( ${LIB_NAME_CBMEX}
  275. ${LIB_NAME_STATIC}
  276. ${QT_LIBRARIES}
  277. ${Matlab_LIBRARIES}
  278. )
  279. ENDIF( ${BUILD_CBMEX} AND MATLAB_FOUND )
  280. ##
  281. # octave
  282. IF( ${BUILD_CBOCT} AND OCTAVE_FOUND )
  283. MESSAGE ( STATUS "Add cbmex build target using Octave libs at " ${OCTAVE_OCT_LIB_DIR})
  284. IF( WIN32 )
  285. SET ( LIB_SOURCE_CBMEX ${LIB_SOURCE_CBMEX} ../cbmex/cbMex.rc )
  286. ENDIF( WIN32 )
  287. ADD_LIBRARY( ${LIB_NAME_CBOCT} SHARED ${LIB_SOURCE_CBMEX} )
  288. # Want package name to be cbmex without prefix
  289. IF( WIN32 )
  290. # Do not output to Debug/Release directories on Windows
  291. SET_TARGET_PROPERTIES( ${LIB_NAME_CBOCT} PROPERTIES PREFIX "../" )
  292. # Manually export mexFunction because __declspec(dllexport) conflicts with its definition in mex.h
  293. SET_TARGET_PROPERTIES( ${LIB_NAME_CBOCT} PROPERTIES LINK_FLAGS "/EXPORT:mexFunction" )
  294. ELSEIF( APPLE )
  295. SET_TARGET_PROPERTIES( ${LIB_NAME_CBOCT} PROPERTIES PREFIX "" )
  296. # This is for normal users of MATLAB on OSX without homebrew
  297. # so we try to use relative paths to be able to bundle shared libraries
  298. SET_TARGET_PROPERTIES( ${LIB_NAME_CBOCT} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@rpath")
  299. ELSE( WIN32 )
  300. SET_TARGET_PROPERTIES( ${LIB_NAME_CBOCT} PROPERTIES PREFIX "" )
  301. SET_TARGET_PROPERTIES( ${LIB_NAME_CBOCT} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL" )
  302. ENDIF( WIN32 )
  303. SET_TARGET_PROPERTIES( ${LIB_NAME_CBOCT} PROPERTIES SUFFIX .mex)
  304. IF( NOT CBMEX_INSTALL_PREFIX )
  305. SET( CBMEX_INSTALL_PREFIX .)
  306. ENDIF( NOT CBMEX_INSTALL_PREFIX )
  307. # Use static library to build cbmex
  308. ADD_DEPENDENCIES( ${LIB_NAME_CBOCT} ${LIB_NAME_STATIC} )
  309. TARGET_INCLUDE_DIRECTORIES( ${LIB_NAME_CBOCT}
  310. PRIVATE "$<BUILD_INTERFACE:${LIB_INCL_DIRS}>" ${OCTAVE_INCLUDE_DIR}
  311. )
  312. TARGET_LINK_LIBRARIES( ${LIB_NAME_CBOCT} ${LIB_NAME_STATIC} ${QT_LIBRARIES} ${OCTAVE_LIBRARIES} )
  313. ENDIF( ${BUILD_CBOCT} AND OCTAVE_FOUND )
  314. ##
  315. # test
  316. IF(${BUILD_TEST})
  317. ADD_EXECUTABLE( ${TEST_NAME} ${PROJECT_SOURCE_DIR}/cbmex/testcbsdk.cpp )
  318. TARGET_INCLUDE_DIRECTORIES( ${TEST_NAME} PRIVATE "$<BUILD_INTERFACE:${LIB_INCL_DIRS}>")
  319. TARGET_LINK_LIBRARIES( ${TEST_NAME} ${LIB_NAME} )
  320. LIST(APPEND INSTALL_TARGET_LIST ${TEST_NAME})
  321. IF(WIN32)
  322. get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
  323. get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
  324. set(QT5_WINDEPLOYQT_EXECUTABLE "${QT5_WINDEPLOYQT_EXECUTABLE}/windeployqt.exe")
  325. add_custom_command(TARGET ${TEST_NAME} POST_BUILD
  326. COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
  327. ENDIF(WIN32)
  328. ENDIF(${BUILD_TEST})
  329. ##
  330. # n2h5
  331. IF(${BUILD_HDF5} AND HDF5_FOUND )
  332. SET( N2H5_SOURCE
  333. ${PROJECT_SOURCE_DIR}/n2h5/main.cpp
  334. ${PROJECT_SOURCE_DIR}/n2h5/n2h5.cpp
  335. ${PROJECT_SOURCE_DIR}/n2h5/n2h5.h
  336. ${PROJECT_SOURCE_DIR}/n2h5/NevNsx.h
  337. )
  338. MESSAGE ( STATUS "Add n2h5 utility build target")
  339. IF( WIN32 )
  340. SET ( N2H5_SOURCE ${N2H5_SOURCE} ${PROJECT_SOURCE_DIR}/n2h5/res/n2h5_res.rc )
  341. ENDIF( WIN32 )
  342. ADD_EXECUTABLE( ${N2H5_NAME} ${N2H5_SOURCE} )
  343. TARGET_INCLUDE_DIRECTORIES( ${N2H5_NAME} PRIVATE "$<BUILD_INTERFACE:${LIB_INCL_DIRS}>" ${HDF5_INCLUDE_DIRS})
  344. TARGET_LINK_LIBRARIES (${N2H5_NAME} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
  345. LIST(APPEND INSTALL_TARGET_LIST ${N2H5_NAME})
  346. ENDIF(${BUILD_HDF5} AND HDF5_FOUND )
  347. #########################################################################################
  348. # Install libraries, test executable, and headers
  349. # Layout. This works for all platforms:
  350. # * <prefix>/lib*/cmake/<PROJECT-NAME>
  351. # * <prefix>/lib*/
  352. # * <prefix>/include/
  353. set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
  354. # MATLAB / octave products go here
  355. set(MEX_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/matlab")
  356. set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
  357. # Configuration
  358. set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
  359. set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
  360. set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
  361. # Include module with function 'write_basic_package_version_file'
  362. include(CMakePackageConfigHelpers)
  363. # Configure '<PROJECT-NAME>ConfigVersion.cmake'
  364. # Use:
  365. # * PROJECT_VERSION
  366. write_basic_package_version_file(
  367. "${version_config}" COMPATIBILITY SameMajorVersion
  368. )
  369. # Configure '<PROJECT-NAME>Config.cmake'
  370. # Use variables:
  371. # * TARGETS_EXPORT_NAME
  372. # * PROJECT_NAME
  373. MESSAGE(STATUS "config_install_dir ${config_install_dir} CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR} PACKAGE_CMAKE_INSTALL_LIBDIR ${PACKAGE_INSTALL_LIBDIR} PACKAGE_INCLUDE_INSTALL_DIR ${PACKAGE_INCLUDE_INSTALL_DIR} ${INCLUDE_INSTALL_DIR} ${SYSCONFIG_INSTALL_DIR}")
  374. configure_package_config_file(
  375. "cmake/Config.cmake.in"
  376. "${project_config}"
  377. INSTALL_DESTINATION "${config_install_dir}"
  378. PATH_VARS CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR
  379. )
  380. # Targets:
  381. install(
  382. TARGETS ${INSTALL_TARGET_LIST}
  383. EXPORT "${TARGETS_EXPORT_NAME}"
  384. LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  385. ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  386. RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
  387. INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
  388. )
  389. # mex:
  390. IF( ${BUILD_CBOCT} AND ${OCTAVE_FOUND} )
  391. INSTALL( TARGETS ${LIB_NAME_CBOCT}
  392. RUNTIME DESTINATION ${MEX_INSTALL_DIR}
  393. LIBRARY DESTINATION ${MEX_INSTALL_DIR}
  394. ARCHIVE DESTINATION ${MEX_INSTALL_DIR}
  395. )
  396. ENDIF( ${BUILD_CBOCT} AND ${OCTAVE_FOUND} )
  397. IF( ${BUILD_CBMEX} AND ${MATLAB_FOUND} )
  398. INSTALL( TARGETS ${LIB_NAME_CBMEX}
  399. RUNTIME DESTINATION ${MEX_INSTALL_DIR}
  400. LIBRARY DESTINATION ${MEX_INSTALL_DIR}
  401. ARCHIVE DESTINATION ${MEX_INSTALL_DIR}
  402. )
  403. ENDIF( ${BUILD_CBMEX} AND ${MATLAB_FOUND} )
  404. # Headers:
  405. install(
  406. FILES ${PROJECT_SOURCE_DIR}/cbmex/cbsdk.h ${PROJECT_SOURCE_DIR}/cbhwlib/cbhwlib.h
  407. DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
  408. )
  409. # Config
  410. install(
  411. FILES "${project_config}" "${version_config}"
  412. DESTINATION "${config_install_dir}"
  413. )
  414. # Config
  415. # * <prefix>/lib/cmake/CBSDK/CBSDKTargets.cmake
  416. install(
  417. EXPORT "${TARGETS_EXPORT_NAME}"
  418. DESTINATION "${config_install_dir}"
  419. )