Lemma is an Electromagnetics API
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
  2. # add this options before PROJECT keyword
  3. set(CMAKE_DISABLE_SOURCE_CHANGES ON)
  4. set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
  5. # Bug in CMake on Linux, but Linux, Mac, and Win all support shared libraries, no harm in this,
  6. # but remove when warning no longer shows.
  7. # Related to calling find_package before a project is created...
  8. # https://cmake.org/Bug/view.php?id=15999
  9. SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  10. ####################################################################################################
  11. # Lemma versioning, set Major, minor, and patch here #
  12. set(LEMMA_VERSION_MAJOR "0") #
  13. set(LEMMA_VERSION_MINOR "4") #
  14. set(LEMMA_VERSION_PATCH "0") #
  15. set(LEMMA_VERSION "\"${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}\"") #
  16. set(LEMMA_VERSION_NOQUOTES "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}") #
  17. ####################################################################################################
  18. ########################################
  19. # ################################## #
  20. # # Pre-Build checks/ dependencies # #
  21. # ################################## #
  22. ########################################
  23. ## Options--what do you want to do
  24. option ( BUILD_SHARED_LIBS "Shared or static libraries" OFF )
  25. #------------------------------------------------------------------------------
  26. # Set a default build type if none was specified
  27. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  28. message(STATUS "Setting build type to 'Debug' as none was specified.")
  29. set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  30. # Set the possible values of build type for cmake-gui
  31. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  32. "Debug"
  33. "Release"
  34. "MinSizeRel"
  35. "RelWithDebInfo"
  36. )
  37. endif()
  38. option ( LEMMA_ENABLE_TESTING "Turn on unit testing" OFF )
  39. option ( LEMMA_BUILD_EXAMPLES "Compile example Lemma applications" OFF )
  40. option ( LEMMA_USE_OPENMP "Use OpenMP in Lemma" OFF )
  41. option ( LEMMA_BUILD_DOCUMENTATION "Build Doxygen man pages" OFF )
  42. option ( LEMMA_VTK8_SUPPORT "VTK 8.x library for visualisation and grids" OFF )
  43. option ( LEMMA_VTK9_SUPPORT "VTK 9.x library for visualisation and grids" OFF )
  44. option ( LEMMA_PYTHON3_BINDINGS "Compile Python 3 bindings" OFF )
  45. # We end up using this for all builds, TODO remove this variable but follow same path
  46. #option (CMAKE_CROSSCOMPILING "Target different arch than you are on" OFF)
  47. SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMake/ )
  48. SET (CMAKE_CROSSCOMPILING TRUE)
  49. ##########################################################################################
  50. ## Only look for packages where we build them...this makes finding VTK a problem though! #
  51. ##########################################################################################
  52. if (CMAKE_CROSSCOMPILING)
  53. message ( STATUS "Performing SuperBuild")
  54. project (CHECKSUPERBUILD CXX) # Necessary for VTK query
  55. # if ("${CHECKSUPERBUILD_SOURCE_DIR}" STREQUAL "${CHECKSUPERBUILD_BINARY_DIR}")
  56. # message(FATAL_ERROR
  57. # "Lemma (SuperBuild) requires an out of source Build. "
  58. # "Please create a separate binary directory and run CMake there.")
  59. # endif()
  60. find_package (yaml-cpp 0.6 PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH) # Serialisation of classes
  61. find_package (Eigen3 3.3 PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH) # Matrix/Vector & Math
  62. if (LEMMA_PYTHON3_BINDINGS)
  63. find_package(pybind11 PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH) # Python 3 bindings
  64. endif()
  65. #${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH
  66. if (LEMMA_VTK8_SUPPORT) # Visualisation
  67. find_package (VTK 8.2.0
  68. COMPONENTS
  69. vtkCommonCore
  70. vtkRenderingCore
  71. vtkFiltersCore
  72. vtkFiltersSources
  73. vtkCommonDataModel
  74. vtkFiltersHyperTree
  75. vtkIOXML
  76. vtkIOImage
  77. vtkIOLegacy
  78. vtkIOGeometry
  79. vtkInteractionStyle
  80. vtkRenderingAnnotation
  81. vtkFiltersHybrid
  82. vtkFiltersModeling
  83. vtkRenderingVolumeOpenGL2
  84. QUIET
  85. )
  86. endif()
  87. if (LEMMA_VTK9_SUPPORT) # Visualisation
  88. find_package (VTK 9.0.1
  89. COMPONENTS
  90. CommonCore
  91. RenderingCore
  92. FiltersCore
  93. FiltersSources
  94. CommonDataModel
  95. FiltersHyperTree
  96. IOXML
  97. IOImage
  98. IOLegacy
  99. IOGeometry
  100. InteractionStyle
  101. RenderingAnnotation
  102. FiltersHybrid
  103. FiltersModeling
  104. RenderingVolumeOpenGL2
  105. QUIET
  106. )
  107. endif()
  108. else()
  109. find_package (Eigen3 3.3 QUIET ) # Matrix/Vector & Math
  110. find_package (yaml-cpp 0.6 QUIET ) # Serialisation of classes
  111. if (LEMMA_VTK9_SUPPORT)
  112. find_package (VTK 9.0.1 COMPONENTS
  113. vtkCommonCore
  114. vtkRenderingCore
  115. vtkFiltersCore
  116. vtkFiltersSources
  117. vtkCommonDataModel
  118. vtkFiltersHyperTree
  119. vtkIOXML
  120. vtkIOImage
  121. vtkIOLegacy
  122. vtkIOGeometry
  123. vtkInteractionStyle
  124. vtkRenderingAnnotation
  125. vtkFiltersHybrid
  126. vtkFiltersModeling
  127. vtkRenderingVolumeOpenGL2
  128. QUIET )
  129. endif()
  130. endif()
  131. INCLUDE_DIRECTORIES(${YAML_CPP_INCLUDE_DIR})
  132. #if (VTK_VERSION VERSION_GREATER "8.2.0")
  133. # message( STATUS "${VTK_VERSION} is compatible: ${VTK_VERSION_COMPATIBLE} exact? ${VTK_VERSION_EXACT}" )
  134. # set (VTK_FOUND False)
  135. #endif()
  136. if (VTK_FOUND)
  137. set(volumeRenderer volumerenderer.cxx)
  138. add_definitions(-DLEMMAUSEVTK)
  139. if (LEMMA_VTK8_SUPPORT)
  140. add_definitions(-DLEMMA_VTK8_SUPPORT)
  141. else (LEMMA_VTK9_SUPPORT)
  142. add_definitions(-DLEMMA_VTK9_SUPPORT)
  143. endif()
  144. endif()
  145. if (LEMMA_BUILD_DOCUMENTATION)
  146. find_package(Doxygen REQUIRED)
  147. endif()
  148. ## Optional Dependencies
  149. if (LEMMA_ENABLE_TESTING)
  150. if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/README")
  151. set (CXXTEST_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/" CACHE PATH "" FORCE )
  152. else()
  153. set (CXXTEST_INCLUDE_DIR "CXXTEST_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE )
  154. endif()
  155. if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/bin/cxxtestgen")
  156. set (CXXTEST_PYTHON_TESTGEN_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/bin/cxxtestgen" CACHE PATH "" FORCE )
  157. else()
  158. set (CXXTEST_PYTHON_TESTGEN_EXECUTABLE "CXXTEST_PYTHON_TESTGEN_EXECUTABLE-NOTFOUND" CACHE PATH "" FORCE )
  159. endif()
  160. find_package (CxxTest QUIET) # Unit testing
  161. endif()
  162. message ( STATUS "VTK Found? " ${VTK_FOUND} )
  163. ## Optional Dependencies
  164. if ( NOT Eigen3_FOUND OR
  165. NOT yaml-cpp_FOUND OR
  166. (LEMMA_PYTHON3_BINDINGS AND NOT pybind11_FOUND) OR
  167. (LEMMA_VTK9_SUPPORT AND NOT VTK_FOUND) OR
  168. (LEMMA_ENABLE_TESTING AND NOT CxxTest_FOUND) )
  169. message ( STATUS "Missing hard dependencies have been found, these will be downloaded any compiled." )
  170. message ( STATUS "This necessitates a two step build." )
  171. message ( STATUS "Build these packages first...THEN RERUN CMAKE!" )
  172. project (SUPERBUILD NONE)
  173. # execute the superbuild (this script will be invoked again without the
  174. # USE_SUPERBUILD option this time)
  175. include (CMake/SuperBuild.cmake)
  176. return() # stop processing this file further
  177. else()
  178. #project (Blah) # <-- YOUR PROJECT NAME HERE
  179. message( STATUS "Everything was found, happy Lemma-ing" )
  180. endif()
  181. # Mac OSX RPATH is weird
  182. # enable @rpath in the install name for any shared library being built
  183. # note: it is planned that a future version of CMake will enable this by default
  184. if(POLICY CMP0015)
  185. cmake_policy(SET CMP0015 NEW)
  186. endif()
  187. set(CMAKE_MACOSX_RPATH 1)
  188. project (Lemma CXX)
  189. # Disallow in-source build
  190. if ("${Lemma_SOURCE_DIR}" STREQUAL "${Lemma_BINARY_DIR}")
  191. message(FATAL_ERROR
  192. "Lemma requires an out of source Build. "
  193. "Please create a separate binary directory and run CMake there.")
  194. endif()
  195. if(CXXTEST_FOUND)
  196. if (LEMMA_ENABLE_TESTING)
  197. include (CTest)
  198. enable_testing()
  199. endif()
  200. endif()
  201. ##############################
  202. # required external programs # for downloading packages
  203. ##############################
  204. FIND_PROGRAM(HAVEGIT git
  205. PATHS /usr/bin/ /bin ENV PATH NO_DEFAULT_PATH
  206. )
  207. if(NOT HAVEGIT)
  208. message(FATAL_ERROR "Lemma requires that git is installed and in the path of your machine")
  209. endif(NOT HAVEGIT)
  210. if(BUILD_SHARED_LIBS)
  211. set(LABEL_SUFFIX "shared")
  212. else()
  213. set(LABEL_SUFFIX "static")
  214. endif()
  215. #######################
  216. # Lemma Configuration #
  217. #######################
  218. #############################
  219. # Look for Ki Ha Lee (EM1D) #
  220. #############################
  221. FIND_LIBRARY( KIHA_EM1D kihaem1d )
  222. if ( KIHA_EM1D )
  223. add_definitions(-DKIHALEE_EM1D)
  224. endif()
  225. ####################
  226. # Look for Boost
  227. ####################
  228. option (LEMMA_USE_BOOST "Boost is required by gaussian quadrature classes" OFF)
  229. if (LEMMA_USE_BOOST)
  230. find_package(Boost
  231. 1.64.0 # Minimum or EXACT version e.g. 1.36.0
  232. # COMPONENTS math # Boost libraries by their canonical name
  233. )
  234. if(Boost_FOUND)
  235. include_directories(${Boost_INCLUDE_DIRS})
  236. find_path( HAVE_BOOST_SPECIAL_FUNCTIONS "boost/math/special_functions.hpp" )
  237. if(HAVE_BOOST_SPECIAL_FUNCTIONS)
  238. add_definitions(-DHAVE_BOOST_SPECIAL_FUNCTIONS)
  239. endif()
  240. else()
  241. message(FATAL_ERROR "Boost was not found, but was requested in CMake.")
  242. endif()
  243. endif()
  244. if (LEMMA_PYTHON3_BINDINGS)
  245. #find_package(PythonLibs 3.0 REQUIRED)
  246. #find_package(pythoninterp REQUIRED)
  247. find_package(pybind11 REQUIRED)
  248. # find_package(Boost 1.64.0 REQUIRED COMPONENTS system python3 numpy3)
  249. # Is this OK for portability of non-python libraries
  250. #include_directories(${PYTHON_INCLUDE_DIRS})
  251. #include_directories(${Boost_INCLUDE_DIRS})
  252. install ( FILES python/setup.py DESTINATION ${CMAKE_INSTALL_PREFIX}/pyLemma/ )
  253. install ( FILES python/long.md DESTINATION ${CMAKE_INSTALL_PREFIX}/pyLemma/ )
  254. install ( FILES python/publish.sh DESTINATION ${CMAKE_INSTALL_PREFIX}/pyLemma/ )
  255. install ( FILES README.md DESTINATION ${CMAKE_INSTALL_PREFIX}/pyLemma/ )
  256. install ( DIRECTORY python/pyLemma DESTINATION ${CMAKE_INSTALL_PREFIX}/pyLemma/ )
  257. endif()
  258. ####################
  259. # MSVC error fix
  260. ####################
  261. option( MSVC_EXTENDED_ALIGNMENT "Turn on MSVC compiler definition _ENABLE_EXTENDED_ALIGNED_STORAGE " OFF )
  262. if (MSVC_EXTENDED_ALIGNMENT)
  263. add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
  264. #if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
  265. # SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")
  266. # SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LTCG")
  267. # SET(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /LTCG")
  268. # SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /LTCG")
  269. #endif()
  270. #add_definitions(-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE)
  271. #set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
  272. #include(GenerateExportHeader)
  273. endif()
  274. ####################
  275. # Magic rpath flag
  276. ####################
  277. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  278. if (LEMMA_USE_OPENMP)
  279. if(APPLE)
  280. #if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  281. # set(OpenMP_C "${CMAKE_C_COMPILER}")
  282. # set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
  283. # set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5")
  284. # set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES})
  285. # set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES})
  286. # set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES})
  287. #endif()
  288. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  289. find_library( libiomp5 NAMES libiomp5.dylib PATHS "/anaconda3/lib/" REQUIRED )
  290. set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
  291. set(OpenMP_CXX_FLAGS "-fopenmp=libiomp5 -Wno-unused-command-line-argument")
  292. set(OpenMP_CXX_LIB_NAMES "libiomp5") #"libomp" "libgomp" "libiomp5")
  293. #set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  294. #set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  295. set(OpenMP_libiomp5_LIBRARY libiomp5 )# ${OpenMP_CXX_LIB_NAMES})
  296. set(OpenMP_LIBRARIES libiomp5)
  297. link_directories("/anaconda3/lib")
  298. # find_package(OpenMP REQUIRED)
  299. # set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include")
  300. # " -DOpenMP_CXX_LIB_NAMES=\"omp\" -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp/lib/libomp.dylib ")
  301. # set(OpenMP_CXX_LIB_NAMES "omp") # "libgomp" "libiomp5")
  302. # set(OpenMP_libomp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib") #${OpenMP_CXX_LIB_NAMES})
  303. # set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  304. # set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES})
  305. endif()
  306. endif()
  307. if (CMAKE_CROSSCOMPILING)
  308. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
  309. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  310. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fopenmp")
  311. else()
  312. find_package(OpenMP REQUIRED)
  313. if (OPENMP_FOUND)
  314. # include_directories("${OPENMP_INCLUDES}")
  315. link_directories("${OPENMP_LIBRARIES}")
  316. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  317. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  318. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
  319. endif()
  320. endif()
  321. add_definitions(-DLEMMAUSEOMP) # -DEIGEN_DONT_VECTORIZE)
  322. endif()
  323. configure_file (
  324. "${PROJECT_SOURCE_DIR}/config/LemmaConfig.h.in"
  325. "${PROJECT_BINARY_DIR}/include/LemmaConfig.h"
  326. )
  327. install ( FILES ${PROJECT_BINARY_DIR}/include/LemmaConfig.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/ )
  328. include_directories("${PROJECT_BINARY_DIR}/include")
  329. include_directories ("${CMAKE_INSTALL_PREFIX}/include/")
  330. link_directories ("${CMAKE_INSTALL_PREFIX}/lib/")
  331. ##############
  332. # gprof hack #
  333. ##############
  334. #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
  335. ########################################################################
  336. # Build Modules
  337. add_subdirectory (Modules)
  338. #######################################################################
  339. # CXXTEST Framework
  340. if(CXXTEST_FOUND)
  341. if (LEMMA_ENABLE_TESTING)
  342. include (CTest)
  343. enable_testing()
  344. endif()
  345. endif()
  346. ########################################################################
  347. # add a target to generate API documentation with Doxyfile.in
  348. # ALL make documentation build by default if possible
  349. if (LEMMA_BUILD_DOCUMENTATION)
  350. find_package(Doxygen)
  351. if(DOXYGEN_FOUND)
  352. message( STATUS "LEMMA_BUILD_DOCUMENTATION must be positive" )
  353. # Custom header and footer option, enable in Doxygen
  354. # file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Documentation/header.html
  355. # DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Documentation/header.html
  356. # )
  357. # file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Documentation/footer.html
  358. # DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Documentation/footer.html
  359. # )
  360. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Documentation/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile @ONLY)
  361. add_custom_target(doc
  362. ALL
  363. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile
  364. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  365. COMMENT "Generating API documentation with Doxygen" VERBATIM
  366. )
  367. endif(DOXYGEN_FOUND)
  368. endif (LEMMA_BUILD_DOCUMENTATION)
  369. # vim: set tabstop=4 shiftwidth=4 expandtab: