Main Lemma Repository
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CMakeLists.txt 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
  2. # Bug in CMake on Linux, but Linux, Mac, and Win all support shared libraries, no harm in this,
  3. # but remove when warning no longer shows.
  4. # Related to calling find_package before a project is created...
  5. # https://cmake.org/Bug/view.php?id=15999
  6. SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  7. ####################################################################################################
  8. # Lemma versioning, set Major, minor, and patch here #
  9. set(LEMMA_VERSION_MAJOR "0") #
  10. set(LEMMA_VERSION_MINOR "2") #
  11. set(LEMMA_VERSION_PATCH "2") #
  12. set(LEMMA_VERSION "\"${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}\"") #
  13. set(LEMMA_VERSION_NOQUOTES "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}") #
  14. ####################################################################################################
  15. ########################################
  16. # ################################## #
  17. # # Pre-Build checks/ dependencies # #
  18. # ################################## #
  19. ########################################
  20. ## Options--what do you want to do
  21. option ( BUILD_SHARED_LIBS "Shared or static libraries" OFF )
  22. option ( LEMMA_ENABLE_TESTING "Turn on unit testing" OFF )
  23. option ( LEMMA_BUILD_EXAMPLES "Compile example Lemma applications" OFF )
  24. option ( LEMMA_USE_OPENMP "Use OpenMP in Lemma" OFF )
  25. option ( LEMMA_BUILD_DOCUMENTATION "Build Doxygen man pages" OFF )
  26. option (LEMMA_VTK6_SUPPORT "VTK 6.x library for visualisation and grids" OFF)
  27. option (LEMMA_VTK7_SUPPORT "VTK 7.x library for visualisation and grids" OFF)
  28. option (LEMMA_VTK8_SUPPORT "VTK 8.x library for visualisation and grids" OFF)
  29. #option (CMAKE_CROSSCOMPILING "Target different arch than you are on" OFF)
  30. ##########################################################################################
  31. ## Only look for packages where we build them...this makes finding VTK a problem though! #
  32. ##########################################################################################
  33. if (CMAKE_CROSSCOMPILING)
  34. message ( STATUS "Cross-compiling! Only searching in install directory for components." )
  35. SET( CMAKE_FIND_ROOT_PATH ONLY ${CMAKE_INSTALL_PREFIX})
  36. SET( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
  37. SET( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
  38. SET( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
  39. UNSET( Eigen3_DIR CACHE )
  40. UNSET( yaml-cpp_DIR CACHE )
  41. find_package (Eigen3 3.3 )# QUIET) # Matrix/Vector & Math
  42. find_package (yaml-cpp 0.6 ) #QUIET ) # Serialisation of classes
  43. endif()
  44. find_package (Eigen3 3.3 )# QUIET) # Matrix/Vector & Math
  45. find_package (yaml-cpp 0.6 ) #QUIET ) # Serialisation of classes
  46. INCLUDE_DIRECTORIES(${YAML_CPP_INCLUDE_DIR})
  47. if (LEMMA_BUILD_DOCUMENTATION)
  48. find_package(Doxygen REQUIRED)
  49. endif()
  50. ## Optional Dependencies
  51. if (LEMMA_ENABLE_TESTING)
  52. if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/README")
  53. set (CXXTEST_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/" CACHE PATH "" FORCE )
  54. else()
  55. set (CXXTEST_INCLUDE_DIR "CXXTEST_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE )
  56. endif()
  57. if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/bin/cxxtestgen")
  58. set (CXXTEST_PYTHON_TESTGEN_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/bin/cxxtestgen" CACHE PATH "" FORCE )
  59. else()
  60. set (CXXTEST_PYTHON_TESTGEN_EXECUTABLE "CXXTEST_PYTHON_TESTGEN_EXECUTABLE-NOTFOUND" CACHE PATH "" FORCE )
  61. endif()
  62. find_package (CxxTest QUIET) # Unit testing
  63. endif()
  64. #######################################################################
  65. # CXXTEST Framework
  66. if(CXXTEST_FOUND)
  67. if (LEMMA_ENABLE_TESTING)
  68. #include_directories(${CXXTEST_INCLUDE_DIR}) # Add this in testing CMakeLists.txt instead, cleaner
  69. enable_testing()
  70. endif()
  71. endif()
  72. ## Optional Dependencies
  73. if ( NOT Eigen3_FOUND OR
  74. NOT yaml-cpp_FOUND OR
  75. (LEMMA_ENABLE_TESTING AND NOT CxxTest_FOUND) )
  76. message ( STATUS "Missing hard dependencies have been found, these will be downloaded any compiled." )
  77. message ( STATUS "This necessitates a two step build." )
  78. message ( STATUS "Build these packages first...THEN RERUN CMAKE!" )
  79. project (SUPERBUILD NONE)
  80. # execute the superbuild (this script will be invoked again without the
  81. # USE_SUPERBUILD option this time)
  82. include (CMake/SuperBuild.cmake)
  83. return() # stop processing this file further
  84. else()
  85. #project (Blah) # <-- YOUR PROJECT NAME HERE
  86. message( STATUS "Everything was found, happy Lemma-ing" )
  87. endif()
  88. # Mac OSX RPATH is weird
  89. # enable @rpath in the install name for any shared library being built
  90. # note: it is planned that a future version of CMake will enable this by default
  91. if(POLICY CMP0015)
  92. cmake_policy(SET CMP0015 NEW)
  93. endif()
  94. set(CMAKE_MACOSX_RPATH 1)
  95. project (Lemma CXX)
  96. # Disallow in-source build
  97. if ("${Lemma_SOURCE_DIR}" STREQUAL "${Lemma_BINARY_DIR}")
  98. message(FATAL_ERROR
  99. "Lemma requires an out of source Build. "
  100. "Please create a separate binary directory and run CMake there.")
  101. endif()
  102. ##############################
  103. # required external programs # for downloading packages
  104. ##############################
  105. FIND_PROGRAM(HAVEGIT git
  106. PATHS /usr/bin/ /bin ENV PATH NO_DEFAULT_PATH
  107. )
  108. if(NOT HAVEGIT)
  109. message(FATAL_ERROR "Lemma requires that git is installed and in the path of your machine")
  110. endif(NOT HAVEGIT)
  111. if(BUILD_SHARED_LIBS)
  112. set(LABEL_SUFFIX "shared")
  113. else()
  114. set(LABEL_SUFFIX "static")
  115. endif()
  116. if(NOT CMAKE_BUILD_TYPE)
  117. set(CMAKE_BUILD_TYPE "Release" CACHE STRING
  118. "Choose the type of build, options are: Debug Release
  119. RelWithDebInfo MinSizeRel."
  120. FORCE)
  121. endif(NOT CMAKE_BUILD_TYPE)
  122. ###################
  123. # External Projects
  124. ###################
  125. # We don't build VTK, it is too heavy.
  126. if ( LEMMA_VTK6_SUPPORT )
  127. #find_package(VTK 6 REQUIRED NO_MODULE)
  128. find_package(VTK 6.0 COMPONENTS vtkCommonCore vtkRenderingCore vtkFiltersCore vtkFiltersSources
  129. vtkCommonDataModel vtkFiltersHyperTree vtkIOXML vtkIOImage vtkIOLegacy vtkInteractionStyle
  130. vtkRenderingAnnotation vtkFiltersHybrid vtkFiltersModeling vtkRenderingVolumeOpenGL NO_MODULE)
  131. set(volumeRenderer volumerenderer.cxx)
  132. include(${VTK_USE_FILE})
  133. add_compile_options(-DLEMMAUSEVTK)
  134. # Compile Matplot_vtk if VTK is present
  135. #add_subdirectory(Matplot_vtk)
  136. #include_directories ("${PROJECT_SOURCE_DIR}/Matplot_vtk")
  137. endif()
  138. if ( LEMMA_VTK7_SUPPORT )
  139. #find_package(VTK 7 REQUIRED NO_MODULE)
  140. find_package(VTK 7.0 COMPONENTS vtkCommonCore vtkRenderingCore vtkFiltersCore vtkFiltersSources
  141. vtkCommonDataModel vtkFiltersHyperTree vtkIOXML vtkIOImage vtkIOLegacy vtkInteractionStyle
  142. vtkRenderingAnnotation vtkFiltersHybrid vtkFiltersModeling vtkRenderingVolumeOpenGL2 NO_MODULE)
  143. set(volumeRenderer volumerenderer.cxx)
  144. if (VTK_FOUND)
  145. message(STATUS "VTK 7 was found! ")
  146. include(${VTK_USE_FILE})
  147. #add_compile_options(-DLEMMAUSEVTK)
  148. #target_compile_definitions( lemmacore PRIVATE LEMMAUSEVTK=1 )
  149. add_definitions(-DLEMMAUSEVTK)
  150. else()
  151. ExternalProject_Add(VTK
  152. GIT_REPOSITORY "https://gitlab.kitware.com/vtk/vtk.git"
  153. GIT_TAG "v7.1.1"
  154. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/vtk7
  155. CMAKE_ARGS
  156. -DBUILD_SHARED_LIBS:BOOL=ON
  157. -DBUILD_EXAMPLES:BOOL=OFF
  158. -DBUILD_TESTING:BOOL=OFF
  159. -DVTK_Group_Web:BOOL=OFF
  160. -DModule_vtkImagingMath:BOOL=ON
  161. LOG_DOWNLOAD 0
  162. LOG_UPDATE 0
  163. )
  164. endif()
  165. endif()
  166. if ( LEMMA_VTK8_SUPPORT )
  167. find_package(VTK 8.0 COMPONENTS vtkCommonCore vtkRenderingCore vtkFiltersCore vtkFiltersSources
  168. vtkCommonDataModel vtkFiltersHyperTree vtkIOXML vtkIOImage vtkIOLegacy vtkInteractionStyle
  169. vtkRenderingAnnotation vtkFiltersHybrid vtkFiltersModeling vtkRenderingVolumeOpenGL2 NO_MODULE)
  170. if (VTK_FOUND)
  171. message(STATUS "VTK 8 was found! ")
  172. set(volumeRenderer volumerenderer.cxx)
  173. include(${VTK_USE_FILE})
  174. else()
  175. message( STATUS "External build of VTK 8 has been added, this may take some time to build." )
  176. ExternalProject_Add(VTK8
  177. GIT_REPOSITORY "https://gitlab.kitware.com/vtk/vtk.git"
  178. GIT_TAG "v8.1.0"
  179. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/vtk8
  180. CMAKE_ARGS
  181. -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
  182. -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} /
  183. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} /
  184. -DBUILD_SHARED_LIBS:BOOL=ON /
  185. -DBUILD_EXAMPLES:BOOL=OFF /
  186. -DBUILD_TESTING:BOOL=OFF /
  187. -DVTK_Group_Web:BOOL=OFF /
  188. -DModule_vtkImagingMath:BOOL=ON /
  189. LOG_DOWNLOAD 0 /
  190. LOG_UPDATE 0
  191. )
  192. endif()
  193. add_definitions(-DLEMMAUSEVTK)
  194. endif()
  195. #######################
  196. # Lemma Configuration #
  197. #######################
  198. #############################
  199. # Look for Ki Ha Lee (EM1D) #
  200. #############################
  201. FIND_LIBRARY( KIHA_EM1D kihaem1d )
  202. if ( KIHA_EM1D )
  203. add_definitions(-DKIHALEE_EM1D)
  204. endif()
  205. ####################
  206. # Look for Boost
  207. ####################
  208. option (LEMMA_USE_BOOST "Boost is required by gaussian quadrature classes" OFF)
  209. if (LEMMA_USE_BOOST)
  210. find_package(Boost
  211. 1.58.0 # Minimum or EXACT version e.g. 1.36.0
  212. # COMPONENTS math # Boost libraries by their canonical name
  213. )
  214. if(Boost_FOUND)
  215. include_directories(${Boost_INCLUDE_DIRS})
  216. endif()
  217. find_path( HAVE_BOOST_SPECIAL_FUNCTIONS "boost/math/special_functions.hpp" )
  218. if(HAVE_BOOST_SPECIAL_FUNCTIONS)
  219. add_compile_options(-DHAVE_BOOST_SPECIAL_FUNCTIONS)
  220. endif()
  221. endif()
  222. ####################
  223. # Magic rpath flag
  224. ####################
  225. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  226. if (LEMMA_USE_OPENMP)
  227. if (CMAKE_CROSSCOMPILING)
  228. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
  229. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  230. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fopenmp")
  231. #
  232. else()
  233. find_package(OpenMP REQUIRED)
  234. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  235. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  236. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
  237. endif()
  238. endif()
  239. configure_file (
  240. "${PROJECT_SOURCE_DIR}/config/LemmaConfig.h.in"
  241. "${PROJECT_BINARY_DIR}/include/LemmaConfig.h"
  242. )
  243. install ( FILES ${PROJECT_BINARY_DIR}/include/LemmaConfig.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/ )
  244. include_directories("${PROJECT_BINARY_DIR}/include")
  245. include_directories ("${CMAKE_INSTALL_PREFIX}/include/")
  246. link_directories ("${CMAKE_INSTALL_PREFIX}/lib/")
  247. ########################################################################
  248. # Build Modules
  249. add_subdirectory (Modules)
  250. ########################################################################
  251. # add a target to generate API documentation with Doxyfile.in
  252. # ALL make documentation build by default if possible
  253. find_package(Doxygen)
  254. if(DOXYGEN_FOUND)
  255. if (LEMMA_BUILD_DOCUMENTATION)
  256. # Custom header and footer option, enable in Doxygen
  257. # file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Documentation/header.html
  258. # DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Documentation/header.html
  259. # )
  260. # file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Documentation/footer.html
  261. # DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Documentation/footer.html
  262. # )
  263. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Documentation/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile @ONLY)
  264. add_custom_target(doc
  265. ALL
  266. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile
  267. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  268. COMMENT "Generating API documentation with Doxygen" VERBATIM
  269. )
  270. endif (LEMMA_BUILD_DOCUMENTATION)
  271. endif(DOXYGEN_FOUND)
  272. # vim: set tabstop=4 shiftwidth=4 expandtab: