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

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