Main Lemma Repository
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CMakeLists.txt 13KB

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