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.

186 lines
7.2 KiB

  1. cmake_minimum_required (VERSION 2.6)
  2. # Set project name
  3. project (mrmc CXX C)
  4. # Set the version number
  5. set (MRMC_CPP_VERSION_MAJOR 1)
  6. set (MRMC_CPP_VERSION_MINOR 0)
  7. # Set all GTest references to the version in the repository and show it as output
  8. set (GTEST_INCLUDE_DIR resources/3rdparty/gtest-1.6.0/include)
  9. set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest.a)
  10. set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest_main.a)
  11. message(STATUS "GTEST_INCLUDE_DIR is ${GTEST_INCLUDE_DIR}")
  12. message(STATUS "GTEST_LIBRARY is ${GTEST_LIBRARY}")
  13. message(STATUS "GTEST_MAIN_LIBRARY is ${GTEST_MAIN_LIBRARY}")
  14. # Set all log4cplus references the version in the repository
  15. set (LOG4CPLUS_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/include)
  16. set (LOG4CPLUS_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/src/liblog4cplus.a)
  17. message(STATUS "LOG4CPLUS_INCLUDE_DIR is ${LOG4CPLUS_INCLUDE_DIR}")
  18. message(STATUS "LOG4CPLUS_LIBRARY is ${LOG4CPLUS_LIBRARY}")
  19. # Set all Eigen references the version in the repository
  20. set(EIGEN3_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/eigen)
  21. message(STATUS "EIGEN3_INCLUDE_DIR is ${EIGEN3_INCLUDE_DIR}")
  22. # Now define all available custom options
  23. option(DEBUG "Sets whether the DEBUG mode is used" ON)
  24. option(USE_POPCNT "Sets whether the popcnt instruction is going to be used." ON)
  25. option(USE_BOOST_STATIC_LIBRARIES "Sets whether the Boost libraries should be linked statically." ON)
  26. option(USE_BOOST_MT_SUFFIX "Sets whether the the Boost libraries have the suffix mt." OFF)
  27. # If the DEBUG option was turned on, we will target a debug version and a release version otherwise
  28. if (DEBUG)
  29. set (CMAKE_BUILD_TYPE "DEBUG")
  30. message(STATUS "Building DEBUG version.")
  31. else()
  32. set (CMAKE_BUILD_TYPE "RELEASE")
  33. message(STATUS "Building RELEASE version.")
  34. endif()
  35. if(CMAKE_COMPILER_IS_GNUCC)
  36. # Set standard flags for GCC
  37. set (CMAKE_CXX_FLAGS "-std=c++0x -Wall -Werror -pedantic")
  38. # Turn on popcnt instruction if possible (yes by default)
  39. if (USE_POPCNT)
  40. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  41. endif(USE_POPCNT)
  42. elseif(MSVC)
  43. else(CLANG)
  44. # Set standard flags for GCC
  45. set (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Werror -pedantic")
  46. # Turn on popcnt instruction if desired (yes by default)
  47. if (USE_POPCNT)
  48. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  49. endif(USE_POPCNT)
  50. endif()
  51. # Add the binary folder to the search path for include files so that we will find mrmc-config.h
  52. include_directories("${PROJECT_BINARY_DIR}")
  53. # Base path for test files
  54. set(MRMC_CPP_TESTS_BASE_PATH ${PROJECT_SOURCE_DIR}/test)
  55. message(STATUS "MRMC_CPP_TESTS_BASE_PATH is ${MRMC_CPP_TESTS_BASE_PATH}")
  56. # Main Sources
  57. file(GLOB_RECURSE MRMC_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  58. file(GLOB_RECURSE MRMC_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
  59. # Test Sources
  60. # Note that the tests also need the source files, except for the main file
  61. file(GLOB_RECURSE MRMC_TEST_HEADERS ${PROJECT_SOURCE_DIR}/test/*.h)
  62. file(GLOB_RECURSE MRMC_TEST_SOURCES ${PROJECT_SOURCE_DIR}/test/*.cpp ${PROJECT_SOURCE_DIR}/src/*/*.cpp)
  63. # Main Grouping
  64. source_group(Headers FILES ${MRMC_HEADERS})
  65. source_group(Sources FILES ${MRMC_SOURCES})
  66. # Test Grouping
  67. source_group(Headers FILES ${MRMC_TEST_HEADERS})
  68. source_group(Sources FILES ${MRMC_TEST_SOURCES})
  69. # Add base folder for better inclusion paths
  70. include_directories("${PROJECT_SOURCE_DIR}/src")
  71. # Set required external packages
  72. find_package(Threads REQUIRED)
  73. find_package(Doxygen REQUIRED)
  74. #set(Boost_USE_STATIC_LIBS ON)
  75. set(Boost_USE_MULTITHREADED ON)
  76. set(Boost_USE_STATIC_RUNTIME OFF)
  77. find_package(Boost REQUIRED)
  78. if(Boost_FOUND)
  79. if (NOT USE_BOOST_MT_SUFFIX)
  80. set(BOOST_PROGRAM_OPTIONS_LIBRARY "boost_program_options")
  81. else()
  82. set(BOOST_PROGRAM_OPTIONS_LIBRARY "boost_program_options-mt")
  83. endif()
  84. if ((NOT Boost_LIBRARY_DIRS) OR ("${Boost_LIBRARY_DIRS}" STREQUAL ""))
  85. set(Boost_LIBRARY_DIRS "${Boost_INCLUDE_DIRS}/stage/lib")
  86. endif ()
  87. message(STATUS "BOOST_INCLUDE_DIRS is ${Boost_INCLUDE_DIRS}")
  88. message(STATUS "BOOST_LIBRARY_DIRS is ${Boost_LIBRARY_DIRS}")
  89. message(STATUS "BOOST_PROGRAM_OPTIONS_LIBRARY is ${BOOST_PROGRAM_OPTIONS_LIBRARY}")
  90. include_directories(${Boost_INCLUDE_DIRS})
  91. link_directories(${Boost_LIBRARY_DIRS})
  92. # Prepare the static boost libraries in case they were requested
  93. if (USE_BOOST_STATIC_LIBRARIES)
  94. add_library(boost_program_options STATIC IMPORTED)
  95. set_property(TARGET boost_program_options PROPERTY IMPORTED_LOCATION "${Boost_LIBRARY_DIRS}/lib${BOOST_PROGRAM_OPTIONS_LIBRARY}.a")
  96. set_target_properties(boost_program_options PROPERTIES LINKER_LANGUAGE CXX)
  97. endif(USE_BOOST_STATIC_LIBRARIES)
  98. endif(Boost_FOUND)
  99. # Add Eigen to the included directories
  100. include_directories(${EIGEN3_INCLUDE_DIR})
  101. # Add the executables
  102. # Must be created *after* Boost was added because of LINK_DIRECTORIES
  103. add_executable(mrmc ${MRMC_SOURCES} ${MRMC_HEADERS})
  104. add_executable(mrmc-tests ${MRMC_TEST_SOURCES} ${MRMC_TEST_HEADERS})
  105. # Add target link deps for Boost program options
  106. if (USE_BOOST_STATIC_LIBRARIES)
  107. target_link_libraries(mrmc ${BOOST_PROGRAM_OPTIONS_LIBRARY})
  108. target_link_libraries(mrmc-tests ${BOOST_PROGRAM_OPTIONS_LIBRARY})
  109. else()
  110. target_link_libraries(mrmc boost_program_options)
  111. target_link_libraries(mrmc-tests boost_program_options)
  112. endif(USE_BOOST_STATIC_LIBRARIES)
  113. # Add a target to generate API documentation with Doxygen
  114. if(DOXYGEN_FOUND)
  115. set(CMAKE_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc")
  116. string(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${PROJECT_SOURCE_DIR}/src")
  117. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  118. add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMENT "Generating API documentation with Doxygen" VERBATIM)
  119. endif(DOXYGEN_FOUND)
  120. if (GTEST_INCLUDE_DIR)
  121. # For make-based builds, defines make target named test.
  122. # For Visual Studio builds, defines Visual Studio project named RUN_TESTS.
  123. enable_testing()
  124. include_directories(${GTEST_INCLUDE_DIR})
  125. target_link_libraries(mrmc-tests ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY})
  126. add_test(NAME mrmc-tests COMMAND mrmc-tests)
  127. if(MSVC) # VS2012 doesn't support correctly the tuples yet
  128. add_definitions( /D _VARIADIC_MAX=10 )
  129. endif()
  130. endif(GTEST_INCLUDE_DIR)
  131. if (LOG4CPLUS_INCLUDE_DIR)
  132. include_directories(${LOG4CPLUS_INCLUDE_DIR})
  133. target_link_libraries(mrmc ${LOG4CPLUS_LIBRARY})
  134. target_link_libraries(mrmc-tests ${LOG4CPLUS_LIBRARY})
  135. # On Linux, we have to link against librt
  136. if (UNIX AND NOT APPLE)
  137. target_link_libraries(mrmc rt)
  138. target_link_libraries(mrmc-tests rt)
  139. endif(UNIX AND NOT APPLE)
  140. endif(LOG4CPLUS_INCLUDE_DIR)
  141. if (THREADS_FOUND)
  142. include_directories(${THREADS_INCLUDE_DIRS})
  143. target_link_libraries (mrmc ${CMAKE_THREAD_LIBS_INIT})
  144. target_link_libraries (mrmc-tests ${CMAKE_THREAD_LIBS_INIT})
  145. endif(THREADS_FOUND)
  146. # Configure a header file to pass some of the CMake settings to the source code
  147. configure_file (
  148. "${PROJECT_SOURCE_DIR}/mrmc-config.h.in"
  149. "${PROJECT_BINARY_DIR}/mrmc-config.h"
  150. )