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

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