Lemma is an Electromagnetics API
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

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