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.

CMakeLists.txt 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. FIND_PROGRAM(HAVEHG hg
  18. PATHS /usr/bin/ /bin ENV PATH NO_DEFAULT_PATH
  19. )
  20. if(NOT HAVEHG)
  21. message(STATUS "Mercurial (hg) was not found.")
  22. endif(NOT HAVEHG)
  23. option(BUILD_SHARED_LIBS OFF)
  24. if(BUILD_SHARED_LIBS)
  25. set(LABEL_SUFFIX "shared")
  26. else()
  27. set(LABEL_SUFFIX "static")
  28. endif()
  29. if (NOT CMAKE_BUILD_TYPE)
  30. set(CMAKE_BUILD_TYPE "Release")
  31. endif()
  32. ###################
  33. # External Projects
  34. ###################
  35. include(ExternalProject)
  36. # Eigen, this header-library is used extensively for linear algebra, matrices, and arrays
  37. # Mercurial (hg) repo pull, Would it be better to just download latest stable?
  38. if (HAVEHG)
  39. ExternalProject_Add(EIGEN
  40. HG_REPOSITORY "https://bitbucket.org/eigen/eigen/"
  41. UPDATE_COMMAND ""
  42. HG_TAG "default"
  43. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/eigen
  44. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
  45. )
  46. ELSE()
  47. # Stable Eigen, requires manual updating when new releases, but lighter weight.
  48. ExternalProject_Add(EIGEN
  49. #URL "http://bitbucket.org/eigen/eigen/get/3.2.7.tar.gz"
  50. URL "http://bitbucket.org/eigen/eigen/get/default.tar.gz" # tip from repo
  51. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/eigen
  52. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
  53. )
  54. ENDIF()
  55. # Yaml-cpp, this library is used extensively for serialisation of classes (class persistence)
  56. ExternalProject_Add(YAML-CPP
  57. GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git"
  58. GIT_TAG "master"
  59. UPDATE_COMMAND ""
  60. PATCH_COMMAND ""
  61. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/yaml-cpp
  62. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=ON -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
  63. )
  64. add_compile_options(-DHAVE_YAMLCPP)
  65. # tinyxml2, this library is used for XML IO
  66. option( LEMMA_TINYXML_SUPPORT "MATIO library support for MATLAB .mat files" OFF)
  67. if ( LEMMA_TINYXML_SUPPORT )
  68. ExternalProject_Add(TINYXML2
  69. GIT_REPOSITORY "https://github.com/leethomason/tinyxml2.git"
  70. GIT_TAG "master"
  71. UPDATE_COMMAND ""
  72. PATCH_COMMAND ""
  73. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/tinyxml2
  74. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON
  75. #-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
  76. )
  77. add_compile_options(-DTINYXMLSUPPORT)
  78. endif()
  79. option( LEMMA_MATIO_SUPPORT "MATIO library support for MATLAB .mat files" OFF)
  80. if ( LEMMA_MATIO_SUPPORT )
  81. add_compile_options(-DHAVE_MATIO)
  82. # matio, this library is used for MATLAB file IO
  83. ExternalProject_ADD(MATIO
  84. GIT_REPOSITORY "git://git.code.sf.net/p/matio/matio"
  85. GIT_TAG "master"
  86. UPDATE_COMMAND ""
  87. PATCH_COMMAND ""
  88. PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/matio
  89. #CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/external/matio/src/MATIO/autogen.sh && configure
  90. CONFIGURE_COMMAND ./autogen.sh && ./configure --prefix=${CMAKE_INSTALL_PREFIX}
  91. BUILD_IN_SOURCE 1
  92. BUILD_COMMAND ${MAKE}
  93. )
  94. endif()
  95. # We don't build VTK, it is too heavy.
  96. option (LEMMA_VTK6_SUPPORT "VTK library for visualisation and grids" OFF)
  97. if ( LEMMA_VTK6_SUPPORT )
  98. #find_package(VTK 6 REQUIRED NO_MODULE)
  99. find_package(VTK 6.0 COMPONENTS vtkCommonCore vtkRenderingCore vtkFiltersCore vtkFiltersSources
  100. vtkCommonDataModel vtkFiltersHyperTree vtkIOXML vtkIOImage vtkIOLegacy vtkInteractionStyle
  101. vtkRenderingAnnotation vtkFiltersHybrid vtkFiltersModeling vtkRenderingVolumeOpenGL NO_MODULE)
  102. set(volumeRenderer volumerenderer.cxx)
  103. include(${VTK_USE_FILE})
  104. add_compile_options(-DLEMMAUSEVTK)
  105. # Compile Matplot_vtk if VTK is present
  106. add_subdirectory(Matplot_vtk)
  107. include_directories ("${PROJECT_SOURCE_DIR}/Matplot_vtk")
  108. endif()
  109. option (LEMMA_VTK7_SUPPORT "VTK library for visualisation and grids" OFF)
  110. if ( LEMMA_VTK7_SUPPORT )
  111. #find_package(VTK 7 REQUIRED NO_MODULE)
  112. find_package(VTK 7.0 COMPONENTS vtkCommonCore vtkRenderingCore vtkFiltersCore vtkFiltersSources
  113. vtkCommonDataModel vtkFiltersHyperTree vtkIOXML vtkIOImage vtkIOLegacy vtkInteractionStyle
  114. vtkRenderingAnnotation vtkFiltersHybrid vtkFiltersModeling vtkRenderingVolumeOpenGL2 NO_MODULE)
  115. set(volumeRenderer volumerenderer.cxx)
  116. include(${VTK_USE_FILE})
  117. add_compile_options(-DLEMMAUSEVTK)
  118. # Compile Matplot_vtk if VTK is present
  119. add_subdirectory(Matplot_vtk)
  120. include_directories ("${PROJECT_SOURCE_DIR}/Matplot_vtk")
  121. endif()
  122. #####################
  123. # Lemma Configuration
  124. #####################
  125. ####################
  126. # Add the c++11 flag
  127. # TODO add compiler specific instructions
  128. include(CheckCXXCompilerFlag)
  129. CHECK_CXX_COMPILER_FLAG(-std=c++14 COMPILER_SUPPORTS_CXX14)
  130. CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11)
  131. if(COMPILER_SUPPORTS_CXX14)
  132. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
  133. elseif(COMPILER_SUPPORTS_CXX11)
  134. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  135. else()
  136. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 or C++14 support. Please use a different C++ compiler.")
  137. endif()
  138. option( LEMMA_USE_OPENMP "Use OpenMP in Lemma" OFF)
  139. CHECK_CXX_COMPILER_FLAG(-fopenmp COMPILER_SUPPORTS_OPENMP)
  140. if(COMPILER_SUPPORTS_OPENMP AND LEMMA_USE_OPENMP )
  141. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -DLEMMAUSEOMP")
  142. endif()
  143. set(LEMMA_VERSION_MAJOR "0")
  144. set(LEMMA_VERSION_MINOR "1")
  145. set(LEMMA_VERSION_PATCH "1")
  146. set(LEMMA_VERSION "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}")
  147. configure_file (
  148. "${PROJECT_SOURCE_DIR}/include/LemmaConfig.h.in"
  149. "${PROJECT_BINARY_DIR}/include/LemmaConfig.h"
  150. )
  151. include_directories("${PROJECT_BINARY_DIR}/include")
  152. include_directories ("${PROJECT_SOURCE_DIR}/LemmaCore/include")
  153. include_directories ("${CMAKE_INSTALL_PREFIX}/include/eigen3")
  154. include_directories ("${CMAKE_INSTALL_PREFIX}/include/")
  155. link_directories ("${CMAKE_INSTALL_PREFIX}/lib/")
  156. option (LEMMA_ENABLE_TESTING "Turn on unit testing" ON)
  157. if (LEMMA_ENABLE_TESTING)
  158. find_package(CxxTest REQUIRED)
  159. if(CXXTEST_FOUND)
  160. include_directories(${CXXTEST_INCLUDE_DIR})
  161. enable_testing()
  162. #CXXTEST_ADD_TEST(tester_executable runner.cpp
  163. # ${CMAKE_CURRENT_SOURCE_DIR}/src/myTestsuite.h)
  164. CXXTEST_ADD_TEST(unittest_foo foo_test.cc
  165. ${CMAKE_CURRENT_SOURCE_DIR}/src/myTestSuite.h)
  166. #target_link_libraries(unittest_foo foo) # as needed
  167. else()
  168. message(FATAL_ERROR "CxxTest not found.")
  169. endif()
  170. endif()
  171. add_subdirectory (LemmaCore)
  172. ########################################################################
  173. # Build Modules
  174. add_subdirectory (Modules)
  175. ########################################################################
  176. #
  177. include_directories(${CMAKE_INSTALL_PREFIX}/include)
  178. add_executable(Hello "${PROJECT_SOURCE_DIR}/src/test.cpp")
  179. target_link_libraries(Hello lemmacore)
  180. add_dependencies(Hello YAML-CPP)
  181. # add a target to generate API documentation with Doxygen
  182. # ALL make documentation build by default if possible
  183. find_package(Doxygen)
  184. if(DOXYGEN_FOUND)
  185. option( LEMMA_BUILD_DOCUMENTATION "Build Doxygen man pages" OFF )
  186. if (LEMMA_BUILD_DOCUMENTATION)
  187. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Documentation/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile @ONLY)
  188. add_custom_target(doc
  189. ALL
  190. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Documentation/Doxyfile
  191. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  192. COMMENT "Generating API documentation with Doxygen" VERBATIM
  193. )
  194. endif (LEMMA_BUILD_DOCUMENTATION)
  195. endif(DOXYGEN_FOUND)