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

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