Main Lemma Repository
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CMakeLists.txt 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
  2. # add this options before PROJECT keyword
  3. set(CMAKE_DISABLE_SOURCE_CHANGES ON)
  4. set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
  5. # Bug in CMake on Linux, but Linux, Mac, and Win all support shared libraries, no harm in this,
  6. # but remove when warning no longer shows.
  7. # Related to calling find_package before a project is created...
  8. # https://cmake.org/Bug/view.php?id=15999
  9. SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  10. ####################################################################################################
  11. # Lemma versioning, set Major, minor, and patch here #
  12. set(LEMMA_VERSION_MAJOR "0") #
  13. set(LEMMA_VERSION_MINOR "3") #
  14. set(LEMMA_VERSION_PATCH "1") #
  15. set(LEMMA_VERSION "\"${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}\"") #
  16. set(LEMMA_VERSION_NOQUOTES "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}") #
  17. ####################################################################################################
  18. ########################################
  19. # ################################## #
  20. # # Pre-Build checks/ dependencies # #
  21. # ################################## #
  22. ########################################
  23. ## Options--what do you want to do
  24. option ( BUILD_SHARED_LIBS "Shared or static libraries" OFF )
  25. #------------------------------------------------------------------------------
  26. # Set a default build type if none was specified
  27. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  28. message(STATUS "Setting build type to 'Debug' as none was specified.")
  29. set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  30. # Set the possible values of build type for cmake-gui
  31. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  32. "Debug"
  33. "Release"
  34. "MinSizeRel"
  35. "RelWithDebInfo"
  36. )
  37. endif()
  38. option ( LEMMA_ENABLE_TESTING "Turn on unit testing" OFF )
  39. option ( LEMMA_BUILD_EXAMPLES "Compile example Lemma applications" OFF )
  40. option ( LEMMA_USE_OPENMP "Use OpenMP in Lemma" OFF )
  41. option ( LEMMA_BUILD_DOCUMENTATION "Build Doxygen man pages" OFF )
  42. option ( LEMMA_VTK8_SUPPORT "VTK 8.x library for visualisation and grids" OFF )
  43. option ( LEMMA_PYTHON3_BINDINGS "Compile Python 3 bindings" OFF )
  44. # We end up using this for all builds, TODO remove this variable but follow same path
  45. #option (CMAKE_CROSSCOMPILING "Target different arch than you are on" OFF)
  46. SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMake/ )
  47. SET (CMAKE_CROSSCOMPILING TRUE)
  48. ##########################################################################################
  49. ## Only look for packages where we build them...this makes finding VTK a problem though! #
  50. ##########################################################################################
  51. if (CMAKE_CROSSCOMPILING)
  52. message ( STATUS "Performing SuperBuild")
  53. project (CHECKSUPERBUILD CXX) # Necessary for VTK query
  54. # if ("${CHECKSUPERBUILD_SOURCE_DIR}" STREQUAL "${CHECKSUPERBUILD_BINARY_DIR}")
  55. # message(FATAL_ERROR
  56. # "Lemma (SuperBuild) requires an out of source Build. "
  57. # "Please create a separate binary directory and run CMake there.")
  58. # endif()
  59. find_package (yaml-cpp 0.6 PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH) # Serialisation of classes
  60. find_package (Eigen3 3.3 PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH) # Matrix/Vector & Math
  61. #${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH
  62. if (LEMMA_VTK8_SUPPORT) # Visualisation
  63. find_package (VTK 8.2.0
  64. COMPONENTS
  65. vtkCommonCore
  66. vtkRenderingCore
  67. vtkFiltersCore
  68. vtkFiltersSources
  69. vtkCommonDataModel
  70. vtkFiltersHyperTree
  71. vtkIOXML
  72. vtkIOImage
  73. vtkIOLegacy
  74. vtkIOGeometry
  75. vtkInteractionStyle
  76. vtkRenderingAnnotation
  77. vtkFiltersHybrid
  78. vtkFiltersModeling
  79. vtkRenderingVolumeOpenGL2
  80. QUIET
  81. )
  82. endif()
  83. else()
  84. find_package (Eigen3 3.3 QUIET ) # Matrix/Vector & Math
  85. find_package (yaml-cpp 0.6 QUIET ) # Serialisation of classes
  86. if (LEMMA_VTK8_SUPPORT)
  87. find_package (VTK 8.2.0 COMPONENTS
  88. vtkCommonCore
  89. vtkRenderingCore
  90. vtkFiltersCore
  91. vtkFiltersSources
  92. vtkCommonDataModel
  93. vtkFiltersHyperTree
  94. vtkIOXML
  95. vtkIOImage
  96. vtkIOLegacy
  97. vtkIOGeometry
  98. vtkInteractionStyle
  99. vtkRenderingAnnotation
  100. vtkFiltersHybrid
  101. vtkFiltersModeling
  102. vtkRenderingVolumeOpenGL2
  103. QUIET )
  104. endif()
  105. endif()
  106. INCLUDE_DIRECTORIES(${YAML_CPP_INCLUDE_DIR})
  107. if (VTK_VERSION VERSION_GREATER "8.2.0")
  108. message( STATUS "${VTK_VERSION} is compatible: ${VTK_VERSION_COMPATIBLE} exact? ${VTK_VERSION_EXACT}" )
  109. set (VTK_FOUND False)
  110. endif()
  111. if (VTK_FOUND)
  112. set(volumeRenderer volumerenderer.cxx)
  113. add_definitions(-DLEMMAUSEVTK)
  114. endif()
  115. if (LEMMA_BUILD_DOCUMENTATION)
  116. find_package(Doxygen REQUIRED)
  117. endif()
  118. ## Optional Dependencies
  119. if (LEMMA_ENABLE_TESTING)
  120. if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/README")
  121. set (CXXTEST_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/" CACHE PATH "" FORCE )
  122. else()
  123. set (CXXTEST_INCLUDE_DIR "CXXTEST_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE )
  124. endif()
  125. if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/bin/cxxtestgen")
  126. set (CXXTEST_PYTHON_TESTGEN_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/bin/cxxtestgen" CACHE PATH "" FORCE )
  127. else()
  128. set (CXXTEST_PYTHON_TESTGEN_EXECUTABLE "CXXTEST_PYTHON_TESTGEN_EXECUTABLE-NOTFOUND" CACHE PATH "" FORCE )
  129. endif()
  130. find_package (CxxTest QUIET) # Unit testing
  131. endif()
  132. message ( STATUS "VTK Found? " ${VTK_FOUND} )
  133. ## Optional Dependencies
  134. if ( NOT Eigen3_FOUND OR
  135. NOT yaml-cpp_FOUND OR
  136. (LEMMA_VTK8_SUPPORT AND NOT VTK_FOUND) OR
  137. (LEMMA_ENABLE_TESTING AND NOT CxxTest_FOUND) )
  138. message ( STATUS "Missing hard dependencies have been found, these will be downloaded any compiled." )
  139. message ( STATUS "This necessitates a two step build." )
  140. message ( STATUS "Build these packages first...THEN RERUN CMAKE!" )
  141. project (SUPERBUILD NONE)
  142. # execute the superbuild (this script will be invoked again without the
  143. # USE_SUPERBUILD option this time)
  144. include (CMake/SuperBuild.cmake)
  145. return() # stop processing this file further
  146. else()
  147. #project (Blah) # <-- YOUR PROJECT NAME HERE
  148. message( STATUS "Everything was found, happy Lemma-ing" )
  149. endif()
  150. # Mac OSX RPATH is weird
  151. # enable @rpath in the install name for any shared library being built
  152. # note: it is planned that a future version of CMake will enable this by default
  153. if(POLICY CMP0015)
  154. cmake_policy(SET CMP0015 NEW)
  155. endif()
  156. set(CMAKE_MACOSX_RPATH 1)
  157. project (Lemma CXX)
  158. # Disallow in-source build
  159. if ("${Lemma_SOURCE_DIR}" STREQUAL "${Lemma_BINARY_DIR}")
  160. message(FATAL_ERROR
  161. "Lemma requires an out of source Build. "
  162. "Please create a separate binary directory and run CMake there.")
  163. endif()
  164. if(CXXTEST_FOUND)
  165. if (LEMMA_ENABLE_TESTING)
  166. include (CTest)
  167. enable_testing()
  168. endif()
  169. endif()
  170. ##############################
  171. # required external programs # for downloading packages
  172. ##############################
  173. FIND_PROGRAM(HAVEGIT git
  174. PATHS /usr/bin/ /bin ENV PATH NO_DEFAULT_PATH
  175. )
  176. if(NOT HAVEGIT)
  177. message(FATAL_ERROR "Lemma requires that git is installed and in the path of your machine")
  178. endif(NOT HAVEGIT)
  179. if(BUILD_SHARED_LIBS)
  180. set(LABEL_SUFFIX "shared")
  181. else()
  182. set(LABEL_SUFFIX "static")
  183. endif()
  184. #######################
  185. # Lemma Configuration #
  186. #######################
  187. #############################
  188. # Look for Ki Ha Lee (EM1D) #
  189. #############################
  190. FIND_LIBRARY( KIHA_EM1D kihaem1d )
  191. if ( KIHA_EM1D )
  192. add_definitions(-DKIHALEE_EM1D)
  193. endif()
  194. ####################
  195. # Look for Boost
  196. ####################
  197. option (LEMMA_USE_BOOST "Boost is required by gaussian quadrature classes" OFF)
  198. if (LEMMA_USE_BOOST)
  199. find_package(Boost
  200. 1.64.0 # Minimum or EXACT version e.g. 1.36.0
  201. # COMPONENTS math # Boost libraries by their canonical name
  202. )
  203. if(Boost_FOUND)
  204. include_directories(${Boost_INCLUDE_DIRS})
  205. endif()
  206. find_path( HAVE_BOOST_SPECIAL_FUNCTIONS "boost/math/special_functions.hpp" )
  207. if(HAVE_BOOST_SPECIAL_FUNCTIONS)
  208. add_definitions(-DHAVE_BOOST_SPECIAL_FUNCTIONS)
  209. endif()
  210. find_path( HAVE_BOOST_PROGRESS "boost/progress.hpp" )
  211. if(HAVE_BOOST_PROGRESS)
  212. add_definitions(-DHAVE_BOOST_PROGRESS)
  213. endif()
  214. endif()
  215. if (LEMMA_PYTHON3_BINDINGS)
  216. find_package(PythonLibs 3.0 REQUIRED)
  217. find_package(Boost 1.64.0 REQUIRED COMPONENTS system python3 numpy3)
  218. # Is this OK for portability of non-python libraries
  219. include_directories(${PYTHON_INCLUDE_DIRS})
  220. include_directories(${Boost_INCLUDE_DIRS})
  221. endif()
  222. ####################
  223. # MSVC error fix
  224. ####################
  225. option( MSVC_EXTENDED_ALIGNMENT "Turn on MSVC compiler definition _ENABLE_EXTENDED_ALIGNED_STORAGE " OFF )
  226. if (MSVC_EXTENDED_ALIGNMENT)
  227. add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
  228. endif()
  229. ####################
  230. # Magic rpath flag
  231. ####################
  232. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  233. if (LEMMA_USE_OPENMP)
  234. if(APPLE)
  235. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  236. set(OpenMP_C "${CMAKE_C_COMPILER}")
  237. set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
  238. set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5")
  239. set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES})
  240. set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES})
  241. set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES})
  242. endif()
  243. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  244. set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
  245. set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
  246. set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5")
  247. set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  248. set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  249. set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  250. # set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include")
  251. # " -DOpenMP_CXX_LIB_NAMES=\"omp\" -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp/lib/libomp.dylib ")
  252. # set(OpenMP_CXX_LIB_NAMES "omp") # "libgomp" "libiomp5")
  253. # set(OpenMP_libomp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib") #${OpenMP_CXX_LIB_NAMES})
  254. # set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  255. # set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  256. endif()
  257. endif()
  258. if (CMAKE_CROSSCOMPILING)
  259. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
  260. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  261. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fopenmp")
  262. else()
  263. find_package(OpenMP REQUIRED)
  264. if (OPENMP_FOUND)
  265. # include_directories("${OPENMP_INCLUDES}")
  266. link_directories("${OPENMP_LIBRARIES}")
  267. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  268. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  269. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
  270. endif()
  271. endif()
  272. add_definitions(-DLEMMAUSEOMP) # -DEIGEN_DONT_VECTORIZE)
  273. endif()
  274. configure_file (
  275. "${PROJECT_SOURCE_DIR}/config/LemmaConfig.h.in"
  276. "${PROJECT_BINARY_DIR}/include/LemmaConfig.h"
  277. )
  278. install ( FILES ${PROJECT_BINARY_DIR}/include/LemmaConfig.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/ )
  279. include_directories("${PROJECT_BINARY_DIR}/include")
  280. include_directories ("${CMAKE_INSTALL_PREFIX}/include/")
  281. link_directories ("${CMAKE_INSTALL_PREFIX}/lib/")
  282. ########################################################################
  283. # Build Modules
  284. add_subdirectory (Modules)
  285. #######################################################################
  286. # CXXTEST Framework
  287. if(CXXTEST_FOUND)
  288. if (LEMMA_ENABLE_TESTING)
  289. include (CTest)
  290. enable_testing()
  291. endif()
  292. endif()
  293. ########################################################################
  294. # add a target to generate API documentation with Doxyfile.in
  295. # ALL make documentation build by default if possible
  296. find_package(Doxygen)
  297. if(DOXYGEN_FOUND)
  298. if (LEMMA_BUILD_DOCUMENTATION)
  299. # Custom header and footer option, enable in Doxygen
  300. # file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Documentation/header.html
  301. # DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Documentation/header.html
  302. # )
  303. # file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Documentation/footer.html
  304. # DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Documentation/footer.html
  305. # )
  306. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Documentation/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile @ONLY)
  307. add_custom_target(doc
  308. ALL
  309. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile
  310. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  311. COMMENT "Generating API documentation with Doxygen" VERBATIM
  312. )
  313. endif (LEMMA_BUILD_DOCUMENTATION)
  314. endif(DOXYGEN_FOUND)
  315. # vim: set tabstop=4 shiftwidth=4 expandtab: