Lemma is an Electromagnetics API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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