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 12KB

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