CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. ########################################################################
  2. # Project setup
  3. ########################################################################
  4. cmake_minimum_required(VERSION 3.1.0)
  5. project(Pothos)
  6. enable_language(CXX)
  7. enable_testing()
  8. ########################################################################
  9. # gather version information
  10. # packagers may specify -DPOTHOS_EXTVER="foo" to replace the git hash
  11. ########################################################################
  12. file(READ "${PROJECT_SOURCE_DIR}/Changelog.txt" changelog_txt)
  13. string(REGEX MATCH "Release ([0-9]+\\.[0-9]+\\.[0-9]+) \\(" CHANGELOG_MATCH "${changelog_txt}")
  14. if(NOT CHANGELOG_MATCH)
  15. message(FATAL_ERROR "Failed to extract version number from Changelog.txt")
  16. endif(NOT CHANGELOG_MATCH)
  17. set(POTHOS_LIBVER "${CMAKE_MATCH_1}")
  18. if (NOT POTHOS_EXTVER)
  19. include(${PROJECT_SOURCE_DIR}/cmake/Modules/GetGitRevisionDescription.cmake)
  20. get_git_head_revision(GITREFSPEC GITHASH)
  21. if (GITHASH)
  22. string(SUBSTRING "${GITHASH}" 0 8 GITHASH)
  23. set(POTHOS_EXTVER "g${GITHASH}")
  24. else (GITHASH)
  25. set(POTHOS_EXTVER "unknown")
  26. endif (GITHASH)
  27. endif()
  28. set(POTHOS_VERSION "${POTHOS_LIBVER}-${POTHOS_EXTVER}")
  29. #set in-tree variables for PothosConfig.cmake
  30. set(Pothos_DIR ${PROJECT_SOURCE_DIR}/cmake/Modules)
  31. set(POTHOS_IN_TREE_SOURCE_DIR ${PROJECT_SOURCE_DIR})
  32. #POTHOS_ROOT is compiled into the library to locate the install base.
  33. #By default, the POTHOS_ROOT is set to the CMAKE_INSTALL_PREFIX.
  34. #However users may overload this by specifying -DPOTHOS_ROOT=<path>.
  35. set(POTHOS_ROOT "${CMAKE_INSTALL_PREFIX}" CACHE PATH
  36. "Installation root for Pothos::System::getRootPath()")
  37. file(TO_CMAKE_PATH "${POTHOS_ROOT}" POTHOS_ROOT)
  38. #POTHOS_ROOT_ENV is the name of the environment variable
  39. #which tells Pothos where to find the root installation.
  40. #By default, the environment variable POTHOS_ROOT is used.
  41. #Example: set -DPOTHOS_ROOT_ENV=SNAP for snappy packages.
  42. set(POTHOS_ROOT_ENV "POTHOS_ROOT" CACHE STRING
  43. "Environment variable for Pothos::System::getRootPath()")
  44. #APPDATA_ENV is the name of the environment variable
  45. #which tells Pothos where to find the user's data directory.
  46. #By default, the environment variable APPDATA is used.
  47. #Example: set -DAPPDATA_ENV=SNAP_USER_DATA for snappy packages.
  48. set(APPDATA_ENV "APPDATA" CACHE STRING
  49. "Environment variable for Pothos::System::getUserDataPath()")
  50. include(FeatureSummary)
  51. include(CMakeDependentOption)
  52. ########################################################################
  53. # rpath setup - http://www.cmake.org/Wiki/CMake_RPATH_handling
  54. ########################################################################
  55. # use, i.e. don't skip the full RPATH for the build tree
  56. option(CMAKE_SKIP_BUILD_RPATH "skip rpath build" FALSE)
  57. # when building, don't use the install RPATH already
  58. # (but later on when installing)
  59. option(CMAKE_BUILD_WITH_INSTALL_RPATH "build with install rpath" FALSE)
  60. # the RPATH to be used when installing, but only if it's not a system directory
  61. option(CMAKE_AUTOSET_INSTALL_RPATH TRUE)
  62. if(CMAKE_AUTOSET_INSTALL_RPATH)
  63. LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
  64. IF("${isSystemDir}" STREQUAL "-1")
  65. SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
  66. ENDIF("${isSystemDir}" STREQUAL "-1")
  67. endif(CMAKE_AUTOSET_INSTALL_RPATH)
  68. # add the automatically determined parts of the RPATH
  69. # which point to directories outside the build tree to the install RPATH
  70. option(CMAKE_INSTALL_RPATH_USE_LINK_PATH "build with automatic rpath" TRUE)
  71. if(APPLE)
  72. set(CMAKE_MACOSX_RPATH ON)
  73. endif()
  74. ########################################################################
  75. # POCO C++ utility libraries
  76. ########################################################################
  77. if(NOT ENABLE_INTERNAL_POCO)
  78. include(${PROJECT_SOURCE_DIR}/cmake/Modules/SetupPoco.cmake)
  79. endif()
  80. cmake_dependent_option(ENABLE_INTERNAL_POCO "Enable Poco C++ utility libraries" ON "NOT Poco_FOUND" OFF)
  81. add_feature_info(Poco ENABLE_INTERNAL_POCO "Build internal Poco C++ utility libraries")
  82. set(POCO_DIR poco)
  83. if (ENABLE_INTERNAL_POCO)
  84. message(STATUS "Poco >= 1.5.4 not found - using built-in Poco")
  85. if (NOT EXISTS ${PROJECT_SOURCE_DIR}/${POCO_DIR}/CMakeLists.txt)
  86. message(FATAL_ERROR "poco submodule not configured (git submodule update --init --recursive)")
  87. endif ()
  88. #mark that the in-tree poco build is used
  89. #used by uninstall target and PothosConfig
  90. set(POCO_IN_TREE TRUE)
  91. #disable SetupPoco in PothosConfig module
  92. set(INCLUDED_SETUP_POCO_CMAKE TRUE)
  93. #when in-tree poco is selected, default to a minimum build
  94. #users can specify -DPOCO_MIN_BUILD=TRUE to enable full poco
  95. option(POCO_MIN_BUILD "Minimum build for in-tree Poco" TRUE)
  96. if(POCO_MIN_BUILD)
  97. set(ENABLE_MONGODB OFF CACHE INTERNAL "")
  98. set(ENABLE_PDF OFF CACHE INTERNAL "")
  99. set(ENABLE_NETSSL OFF CACHE INTERNAL "")
  100. set(ENABLE_CRYPTO OFF CACHE INTERNAL "")
  101. set(ENABLE_DATA OFF CACHE INTERNAL "")
  102. set(ENABLE_SEVENZIP OFF CACHE INTERNAL "")
  103. set(ENABLE_ZIP OFF CACHE INTERNAL "")
  104. set(ENABLE_APACHECONNECTOR OFF CACHE INTERNAL "")
  105. endif()
  106. add_subdirectory(${POCO_DIR})
  107. set(Poco_FOUND 1)
  108. set(Poco_INCLUDE_DIRS
  109. ${PROJECT_SOURCE_DIR}/${POCO_DIR}/Foundation/include
  110. ${PROJECT_SOURCE_DIR}/${POCO_DIR}/Util/include
  111. ${PROJECT_SOURCE_DIR}/${POCO_DIR}/XML/include
  112. ${PROJECT_SOURCE_DIR}/${POCO_DIR}/Net/include
  113. )
  114. set(Poco_LIBRARIES
  115. PocoFoundation
  116. PocoUtil
  117. PocoXML
  118. PocoNet
  119. )
  120. #ensure that local headers get precedent over installed headers
  121. include_directories(${Poco_INCLUDE_DIRS})
  122. endif(ENABLE_INTERNAL_POCO)
  123. ########################################################################
  124. # Spuce filter design library
  125. ########################################################################
  126. if(NOT ENABLE_INTERNAL_SPUCE)
  127. find_package(Spuce CONFIG)
  128. endif()
  129. cmake_dependent_option(ENABLE_INTERNAL_SPUCE "Enable Spuce filter design library" ON "NOT Spuce_FOUND" OFF)
  130. add_feature_info(Spuce ENABLE_INTERNAL_SPUCE "Build internal Spuce filter design library")
  131. if (ENABLE_INTERNAL_SPUCE)
  132. message(STATUS "Spuce not found - using built-in Spuce")
  133. if (EXISTS ${PROJECT_SOURCE_DIR}/spuce/CMakeLists.txt)
  134. add_subdirectory(spuce)
  135. set(SPUCE_IN_TREE TRUE)
  136. set(Spuce_FOUND TRUE)
  137. set(Spuce_VERSION "[submodule]")
  138. set(Spuce_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/spuce)
  139. set(Spuce_LIBRARIES spuce)
  140. else ()
  141. message(WARNING "spuce submodule not configured (git submodule update --init --recursive)")
  142. endif ()
  143. endif(ENABLE_INTERNAL_SPUCE)
  144. ########################################################################
  145. # muparserx expression parser
  146. ########################################################################
  147. if(NOT ENABLE_INTERNAL_MUPARSERX)
  148. find_package(muparserx CONFIG)
  149. endif()
  150. cmake_dependent_option(ENABLE_INTERNAL_MUPARSERX "Enable MuparserX expression parser" ON "NOT muparserx_FOUND" OFF)
  151. add_feature_info(MuparserX ENABLE_INTERNAL_MUPARSERX "Build internal MuparserX expression parser")
  152. if (ENABLE_INTERNAL_MUPARSERX)
  153. message(STATUS "muparserx not found - using built-in muparserx")
  154. if (NOT EXISTS ${PROJECT_SOURCE_DIR}/muparserx/CMakeLists.txt)
  155. message(FATAL_ERROR "muparserx submodule not configured (git submodule update --init --recursive)")
  156. endif ()
  157. add_subdirectory(muparserx)
  158. set(MUPARSERX_IN_TREE TRUE)
  159. set(muparserx_FOUND TRUE)
  160. set(muparserx_VERSION "[submodule]")
  161. set(muparserx_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/muparserx/parser)
  162. set(muparserx_LIBRARIES muparserx)
  163. endif(ENABLE_INTERNAL_MUPARSERX)
  164. ########################################################################
  165. # json.hpp header
  166. ########################################################################
  167. find_path(JSON_HPP_INCLUDE_DIR NAMES json.hpp PATH_SUFFIXES nlohmann)
  168. #some of the libraries use this header for development
  169. #its a header only and its extremely easy to just download
  170. #but don't do this for package builds (/usr) the package
  171. #maintainer should do this manually to avoid downloading
  172. if (NOT JSON_HPP_INCLUDE_DIR AND NOT "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr")
  173. if (NOT EXISTS "${PROJECT_BINARY_DIR}/json.hpp")
  174. file(DOWNLOAD "https://raw.githubusercontent.com/nlohmann/json/v2.1.1/src/json.hpp" "${PROJECT_BINARY_DIR}/json.hpp")
  175. endif()
  176. set(JSON_HPP_INCLUDE_DIR "${PROJECT_BINARY_DIR}")
  177. endif ()
  178. if ("${JSON_HPP_INCLUDE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
  179. install(FILES "${PROJECT_BINARY_DIR}/json.hpp" DESTINATION include/nlohmann)
  180. endif()
  181. ########################################################################
  182. # Build the framework library
  183. ########################################################################
  184. cmake_dependent_option(ENABLE_LIBRARY "Enable Pothos Library component" ON "TRUE" OFF)
  185. add_feature_info(Library ENABLE_LIBRARY "The main library for all Pothos projects")
  186. #C++11 is a required language feature for this project
  187. set(CMAKE_CXX_STANDARD 11)
  188. if(ENABLE_LIBRARY)
  189. find_package(Pothos CONFIG REQUIRED)
  190. add_subdirectory(include)
  191. add_subdirectory(lib)
  192. add_subdirectory(cmake/Modules)
  193. add_subdirectory(apps)
  194. add_subdirectory(docs)
  195. endif(ENABLE_LIBRARY)
  196. ########################################################################
  197. ## Build submodule toolkits
  198. ########################################################################
  199. cmake_dependent_option(ENABLE_TOOLKITS "Enable Pothos Toolkits components" ON "ENABLE_LIBRARY" OFF)
  200. add_feature_info(Toolkits ENABLE_TOOLKITS "Pothos data-flow software suite toolkits")
  201. if(ENABLE_TOOLKITS)
  202. foreach(subdir blocks comms python soapy audio flow widgets plotters)
  203. if (EXISTS ${PROJECT_SOURCE_DIR}/${subdir}/CMakeLists.txt)
  204. add_subdirectory(${subdir})
  205. else()
  206. message(WARNING "ENABLE_TOOLKITS: submodule ${subdir} not configured, skipping...")
  207. endif()
  208. endforeach(subdir)
  209. endif(ENABLE_TOOLKITS)
  210. ########################################################################
  211. # uninstall target
  212. ########################################################################
  213. if (POCO_IN_TREE)
  214. # use poco's uninstall target, but overwrite the script
  215. configure_file(
  216. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  217. "${CMAKE_CURRENT_BINARY_DIR}/${POCO_DIR}/cmake_uninstall.cmake"
  218. IMMEDIATE @ONLY)
  219. else (POCO_IN_TREE)
  220. add_custom_target(uninstall
  221. "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  222. configure_file(
  223. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  224. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  225. IMMEDIATE @ONLY)
  226. endif (POCO_IN_TREE)
  227. ########################################################################
  228. # print features summary
  229. ########################################################################
  230. message(STATUS "")
  231. message(STATUS "######################################################")
  232. message(STATUS "## Enabled features")
  233. message(STATUS "######################################################")
  234. feature_summary(WHAT ENABLED_FEATURES)
  235. message(STATUS "######################################################")
  236. message(STATUS "## Disabled features")
  237. message(STATUS "######################################################")
  238. feature_summary(WHAT DISABLED_FEATURES)
  239. message(STATUS "Pothos version: v${POTHOS_VERSION}")
  240. message(STATUS "ABI/so version: v${POTHOS_ABI_VERSION}")
  241. message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")