Main Lemma Repository
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CMakeLists.txt 15KB

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