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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. cmake_minimum_required (VERSION 2.8.12)
  2. # Mac OSX RPATH is weird
  3. # enable @rpath in the install name for any shared library being built
  4. # note: it is planned that a future version of CMake will enable this by default
  5. if(POLICY CMP0015)
  6. cmake_policy(SET CMP0015 NEW)
  7. endif()
  8. set(CMAKE_MACOSX_RPATH 1)
  9. project (Lemma CXX)
  10. # required external programs (for runtime of nix, not buildtime)
  11. FIND_PROGRAM(HAVEGIT git
  12. PATHS /usr/bin/ /bin ENV PATH NO_DEFAULT_PATH
  13. )
  14. if(NOT HAVEGIT)
  15. message(FATAL_ERROR "Lemma requires that git is installed and in the path of your machine")
  16. endif(NOT HAVEGIT)
  17. option(BUILD_SHARED_LIBS OFF)
  18. if(BUILD_SHARED_LIBS)
  19. set(LABEL_SUFFIX "shared")
  20. else()
  21. set(LABEL_SUFFIX "static")
  22. endif()
  23. if(NOT CMAKE_BUILD_TYPE)
  24. set(CMAKE_BUILD_TYPE "Release" CACHE STRING
  25. "Choose the type of build, options are: Debug Release
  26. RelWithDebInfo MinSizeRel."
  27. FORCE)
  28. endif(NOT CMAKE_BUILD_TYPE)
  29. ###################
  30. # External Projects
  31. ###################
  32. include(ExternalProject)
  33. ##########################################################################################
  34. # Eigen, this header-library is used extensively for linear algebra, matrices, and arrays
  35. # Mercurial (hg) repo pull, Would it be better to just download latest stable?
  36. FIND_PROGRAM( HAVEHG hg
  37. PATHS /usr/bin/ /bin ENV PATH NO_DEFAULT_PATH
  38. )
  39. if (HAVEHG)
  40. ExternalProject_Add(EIGEN
  41. HG_REPOSITORY "https://bitbucket.org/eigen/eigen/"
  42. UPDATE_COMMAND ""
  43. HG_TAG "3.3.2" #"default"
  44. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/eigen
  45. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
  46. )
  47. ELSE()
  48. # Use Stable Eigen instead
  49. ExternalProject_Add(EIGEN
  50. #URL "http://bitbucket.org/eigen/eigen/get/default.tar.gz" # tip from repo
  51. URL "http://bitbucket.org/eigen/eigen/get/3.3.2.tar.gz"
  52. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/eigen
  53. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
  54. )
  55. ENDIF()
  56. include_directories ("${CMAKE_INSTALL_PREFIX}/include/eigen3")
  57. #############################################################################################
  58. # Yaml-cpp, this library is used extensively for serialisation of classes (class persistence)
  59. ExternalProject_Add(YAML-CPP
  60. GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git"
  61. GIT_TAG "master" #"release-0.5.3" #"master"
  62. UPDATE_COMMAND ""
  63. PATCH_COMMAND ""
  64. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/yaml-cpp
  65. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} /
  66. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  67. )
  68. add_compile_options(-DHAVE_YAMLCPP)
  69. # CxxTest
  70. find_package(CxxTest)
  71. if (CXXTEST_FOUND)
  72. # Do nothing
  73. else()
  74. ExternalProject_Add(CxxTest
  75. GIT_REPOSITORY "https://github.com/CxxTest/cxxtest.git"
  76. GIT_TAG "master"
  77. UPDATE_COMMAND ""
  78. PATCH_COMMAND ""
  79. CONFIGURE_COMMAND ""
  80. BUILD_COMMAND ""
  81. INSTALL_COMMAND ""
  82. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest
  83. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} /
  84. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  85. )
  86. set (CXXTEST_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/")
  87. set (CXXTEST_PYTHON_TESTGEN_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/bin/cxxtestgen" )
  88. find_package(CxxTest REQUIRED)
  89. endif()
  90. # tinyxml2, this library is used for XML IO
  91. option( LEMMA_TINYXML_SUPPORT "MATIO library support for MATLAB .mat files" OFF)
  92. if ( LEMMA_TINYXML_SUPPORT )
  93. ExternalProject_Add(TINYXML2
  94. GIT_REPOSITORY "https://github.com/leethomason/tinyxml2.git"
  95. GIT_TAG "master"
  96. UPDATE_COMMAND ""
  97. PATCH_COMMAND ""
  98. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/tinyxml2
  99. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} /
  100. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  101. )
  102. add_compile_options(-DTINYXMLSUPPORT)
  103. endif()
  104. option( LEMMA_MATIO_SUPPORT "MATIO library support for MATLAB .mat files" OFF)
  105. if ( LEMMA_MATIO_SUPPORT )
  106. add_compile_options(-DHAVE_MATIO)
  107. # matio, this library is used for MATLAB file IO
  108. ExternalProject_ADD(MATIO
  109. GIT_REPOSITORY "git://git.code.sf.net/p/matio/matio"
  110. GIT_TAG "master"
  111. UPDATE_COMMAND ""
  112. PATCH_COMMAND ""
  113. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/matio
  114. #CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/external/matio/src/MATIO/autogen.sh && configure
  115. CONFIGURE_COMMAND ./autogen.sh && ./configure --prefix=${CMAKE_INSTALL_PREFIX}
  116. BUILD_IN_SOURCE 1
  117. BUILD_COMMAND ${MAKE}
  118. )
  119. endif()
  120. # We don't build VTK, it is too heavy.
  121. option (LEMMA_VTK6_SUPPORT "VTK library for visualisation and grids" OFF)
  122. if ( LEMMA_VTK6_SUPPORT )
  123. #find_package(VTK 6 REQUIRED NO_MODULE)
  124. find_package(VTK 6.0 COMPONENTS vtkCommonCore vtkRenderingCore vtkFiltersCore vtkFiltersSources
  125. vtkCommonDataModel vtkFiltersHyperTree vtkIOXML vtkIOImage vtkIOLegacy vtkInteractionStyle
  126. vtkRenderingAnnotation vtkFiltersHybrid vtkFiltersModeling vtkRenderingVolumeOpenGL NO_MODULE)
  127. set(volumeRenderer volumerenderer.cxx)
  128. include(${VTK_USE_FILE})
  129. add_compile_options(-DLEMMAUSEVTK)
  130. # Compile Matplot_vtk if VTK is present
  131. #add_subdirectory(Matplot_vtk)
  132. #include_directories ("${PROJECT_SOURCE_DIR}/Matplot_vtk")
  133. endif()
  134. option (LEMMA_VTK7_SUPPORT "VTK library for visualisation and grids" OFF)
  135. if ( LEMMA_VTK7_SUPPORT )
  136. #find_package(VTK 7 REQUIRED NO_MODULE)
  137. find_package(VTK 7.0 COMPONENTS vtkCommonCore vtkRenderingCore vtkFiltersCore vtkFiltersSources
  138. vtkCommonDataModel vtkFiltersHyperTree vtkIOXML vtkIOImage vtkIOLegacy vtkInteractionStyle
  139. vtkRenderingAnnotation vtkFiltersHybrid vtkFiltersModeling vtkRenderingVolumeOpenGL2 NO_MODULE)
  140. set(volumeRenderer volumerenderer.cxx)
  141. include(${VTK_USE_FILE})
  142. add_compile_options(-DLEMMAUSEVTK)
  143. # Compile Matplot_vtk if VTK is present
  144. #add_subdirectory(Matplot_vtk)
  145. #include_directories ("${PROJECT_SOURCE_DIR}/Matplot_vtk")
  146. endif()
  147. #####################
  148. # Lemma Configuration
  149. #####################
  150. #####################
  151. # Look for Ki Ha Lee
  152. #####################
  153. FIND_LIBRARY( KIHA_EM1D kihaem1d ) # PATHS ${/home/tirons/local/lib} )
  154. if ( KIHA_EM1D )
  155. add_compile_options(-DKIHALEE_EM1D)
  156. endif()
  157. ####################
  158. # Look for Boost
  159. ####################
  160. option (LEMMA_USE_BOOST "Boost is required by gaussian quadrature classes" OFF)
  161. if (LEMMA_USE_BOOST)
  162. find_package(Boost
  163. 1.58.0 # Minimum or EXACT version e.g. 1.36.0
  164. # COMPONENTS math # Boost libraries by their canonical name
  165. )
  166. if(Boost_FOUND)
  167. include_directories(${Boost_INCLUDE_DIRS})
  168. endif()
  169. find_path( HAVE_BOOST_SPECIAL_FUNCTIONS "boost/math/special_functions.hpp" )
  170. if(HAVE_BOOST_SPECIAL_FUNCTIONS)
  171. add_compile_options(-DHAVE_BOOST_SPECIAL_FUNCTIONS)
  172. endif()
  173. endif()
  174. ####################
  175. # Magic rpath flag
  176. ####################
  177. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  178. ####################
  179. # Add the c++11 flag
  180. # TODO add compiler specific instructions
  181. include(CheckCXXCompilerFlag)
  182. CHECK_CXX_COMPILER_FLAG(-std=c++14 COMPILER_SUPPORTS_CXX14)
  183. CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11)
  184. CHECK_CXX_COMPILER_FLAG(-std=c++0x COMPILER_SUPPORTS_CXX0X)
  185. if(COMPILER_SUPPORTS_CXX14)
  186. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
  187. elseif(COMPILER_SUPPORTS_CXX11)
  188. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  189. elseif(COMPILER_SUPPORTS_CXX0X)
  190. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  191. else()
  192. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 or C++14 support. Please use a different C++ compiler.")
  193. endif()
  194. option( LEMMA_BUILD_EXAMPLES "Compile example Lemma applications" OFF )
  195. option( LEMMA_USE_OPENMP "Use OpenMP in Lemma" OFF)
  196. CHECK_CXX_COMPILER_FLAG(-fopenmp COMPILER_SUPPORTS_OPENMP)
  197. if(COMPILER_SUPPORTS_OPENMP AND LEMMA_USE_OPENMP )
  198. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -DLEMMAUSEOMP")
  199. endif()
  200. set(LEMMA_VERSION_MAJOR "0")
  201. set(LEMMA_VERSION_MINOR "1")
  202. set(LEMMA_VERSION_PATCH "2")
  203. set(LEMMA_VERSION "\"${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}\"")
  204. set(LEMMA_VERSION_NOQUOTES "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}")
  205. configure_file (
  206. "${PROJECT_SOURCE_DIR}/config/LemmaConfig.h.in"
  207. "${PROJECT_BINARY_DIR}/include/LemmaConfig.h"
  208. )
  209. install ( FILES ${PROJECT_BINARY_DIR}/include/LemmaConfig.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/ )
  210. include_directories("${PROJECT_BINARY_DIR}/include")
  211. include_directories ("${CMAKE_INSTALL_PREFIX}/include/")
  212. link_directories ("${CMAKE_INSTALL_PREFIX}/lib/")
  213. #######################################################################
  214. # CXXTEST Framework
  215. if(CXXTEST_FOUND)
  216. option (LEMMA_ENABLE_TESTING "Turn on unit testing" ON)
  217. if (LEMMA_ENABLE_TESTING)
  218. #include_directories(${CXXTEST_INCLUDE_DIR}) # Add this in testing CMakeLists.txt instead, cleaner
  219. enable_testing()
  220. endif()
  221. endif()
  222. ########################################################################
  223. # Build Modules
  224. add_subdirectory (Modules)
  225. ########################################################################
  226. # add a target to generate API documentation with Doxyfile.in
  227. # ALL make documentation build by default if possible
  228. find_package(Doxygen)
  229. if(DOXYGEN_FOUND)
  230. option( LEMMA_BUILD_DOCUMENTATION "Build Doxygen man pages" OFF )
  231. if (LEMMA_BUILD_DOCUMENTATION)
  232. # Custom header and footer option, enable in Doxygen
  233. # file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Documentation/header.html
  234. # DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Documentation/header.html
  235. # )
  236. # file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Documentation/footer.html
  237. # DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Documentation/footer.html
  238. # )
  239. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Documentation/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile @ONLY)
  240. add_custom_target(doc
  241. ALL
  242. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile
  243. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  244. COMMENT "Generating API documentation with Doxygen" VERBATIM
  245. )
  246. endif (LEMMA_BUILD_DOCUMENTATION)
  247. endif(DOXYGEN_FOUND)