Main Lemma Repository
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.

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