Main Lemma Repository
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CMakeLists.txt 13KB

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