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.

199 lines
8.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. if(MSVC)
  10. set (MRMC_LIB_SUFFIX lib)
  11. set (GTEST_LIBRARY_DEBUG ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Debug/gtest.${MRMC_LIB_SUFFIX})
  12. set (GTEST_MAIN_LIBRARY_DEBUG ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Debug/gtest_main.${MRMC_LIB_SUFFIX})
  13. set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Release/gtest.${MRMC_LIB_SUFFIX})
  14. set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Release/gtest_main.${MRMC_LIB_SUFFIX})
  15. set (GTEST_LIBRARIES optimized ${GTEST_LIBRARY} debug ${GTEST_LIBRARY_DEBUG})
  16. else()
  17. set (MRMC_LIB_SUFFIX a)
  18. set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest.${MRMC_LIB_SUFFIX})
  19. set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest_main.${MRMC_LIB_SUFFIX})
  20. set (GTEST_LIBRARIES ${GTEST_LIBRARY}) # as we dont use FindGTest anymore
  21. endif()
  22. message(STATUS "GTEST_INCLUDE_DIR is ${GTEST_INCLUDE_DIR}")
  23. message(STATUS "GTEST_LIBRARY is ${GTEST_LIBRARY}")
  24. message(STATUS "GTEST_MAIN_LIBRARY is ${GTEST_MAIN_LIBRARY}")
  25. # Set all log4cplus references the version in the repository
  26. set (LOG4CPLUS_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/include)
  27. if (MSVC)
  28. set (LOG4CPLUS_LIBRARIES optimized ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/msvc10/x64/bin.Release/log4cplusS.${MRMC_LIB_SUFFIX} debug ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/msvc10/x64/bin.Debug/log4cplusSD.${MRMC_LIB_SUFFIX})
  29. else()
  30. set (LOG4CPLUS_LIBRARIES ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/src/liblog4cplus.${MRMC_LIB_SUFFIX})
  31. endif()
  32. message(STATUS "LOG4CPLUS_INCLUDE_DIR is ${LOG4CPLUS_INCLUDE_DIR}")
  33. message(STATUS "LOG4CPLUS_LIBRARY is ${LOG4CPLUS_LIBRARIES}")
  34. # Set all Eigen references the version in the repository
  35. set(EIGEN3_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/eigen)
  36. message(STATUS "EIGEN3_INCLUDE_DIR is ${EIGEN3_INCLUDE_DIR}")
  37. # Set all Eigen references the version in the repository
  38. set(GMMXX_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/gmm-4.2/include)
  39. message(STATUS "GMMXX_INCLUDE_DIR is ${GMMXX_INCLUDE_DIR}")
  40. # Now define all available custom options
  41. option(DEBUG "Sets whether the DEBUG mode is used" ON)
  42. option(USE_POPCNT "Sets whether the popcnt instruction is going to be used." ON)
  43. option(USE_BOOST_STATIC_LIBRARIES "Sets whether the Boost libraries should be linked statically." ON)
  44. # If the DEBUG option was turned on, we will target a debug version and a release version otherwise
  45. if (DEBUG)
  46. set (CMAKE_BUILD_TYPE "DEBUG")
  47. message(STATUS "Building DEBUG version.")
  48. else()
  49. set (CMAKE_BUILD_TYPE "RELEASE")
  50. message(STATUS "Building RELEASE version.")
  51. endif()
  52. if(CMAKE_COMPILER_IS_GNUCC)
  53. # Set standard flags for GCC
  54. set (CMAKE_CXX_FLAGS "-std=c++0x -Wall -pedantic")
  55. # -Werror is atm removed as this gave some problems with existing code
  56. # May be re-set later
  57. # (Thomas Heinemann, 2012-12-21)
  58. # Turn on popcnt instruction if possible (yes by default)
  59. if (USE_POPCNT)
  60. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  61. endif(USE_POPCNT)
  62. elseif(MSVC)
  63. # required for GMM to compile, ugly error directive in their code
  64. add_definitions(/D_SCL_SECURE_NO_DEPRECATE)
  65. else(CLANG)
  66. # Set standard flags for GCC
  67. set (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Werror -pedantic -Wno-unused-variable")
  68. # Turn on popcnt instruction if desired (yes by default)
  69. if (USE_POPCNT)
  70. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  71. endif(USE_POPCNT)
  72. endif()
  73. # Add the binary folder to the search path for include files so that we will find mrmc-config.h
  74. include_directories("${PROJECT_BINARY_DIR}")
  75. # Base path for test files
  76. set(MRMC_CPP_TESTS_BASE_PATH ${PROJECT_SOURCE_DIR}/test)
  77. message(STATUS "MRMC_CPP_TESTS_BASE_PATH is ${MRMC_CPP_TESTS_BASE_PATH}")
  78. # Main Sources
  79. file(GLOB_RECURSE MRMC_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  80. file(GLOB_RECURSE MRMC_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
  81. # Test Sources
  82. # Note that the tests also need the source files, except for the main file
  83. file(GLOB_RECURSE MRMC_TEST_HEADERS ${PROJECT_SOURCE_DIR}/test/*.h)
  84. file(GLOB_RECURSE MRMC_TEST_SOURCES ${PROJECT_SOURCE_DIR}/test/*.cpp ${PROJECT_SOURCE_DIR}/src/*/*.cpp)
  85. # Main Grouping
  86. source_group(Headers FILES ${MRMC_HEADERS})
  87. source_group(Sources FILES ${MRMC_SOURCES})
  88. # Test Grouping
  89. source_group(Headers FILES ${MRMC_TEST_HEADERS})
  90. source_group(Sources FILES ${MRMC_TEST_SOURCES})
  91. # Add base folder for better inclusion paths
  92. include_directories("${PROJECT_SOURCE_DIR}")
  93. include_directories("${PROJECT_SOURCE_DIR}/src")
  94. # Set required external packages
  95. find_package(Threads REQUIRED)
  96. find_package(Doxygen REQUIRED)
  97. set(Boost_USE_STATIC_LIBS ON)
  98. set(Boost_USE_MULTITHREADED ON)
  99. set(Boost_USE_STATIC_RUNTIME OFF)
  100. find_package(Boost REQUIRED COMPONENTS program_options)
  101. if(Boost_FOUND)
  102. if ((NOT Boost_LIBRARY_DIRS) OR ("${Boost_LIBRARY_DIRS}" STREQUAL ""))
  103. set(Boost_LIBRARY_DIRS "${Boost_INCLUDE_DIRS}/stage/lib")
  104. endif ()
  105. message(STATUS "BOOST_INCLUDE_DIRS is ${Boost_INCLUDE_DIRS}")
  106. message(STATUS "BOOST_LIBRARY_DIRS is ${Boost_LIBRARY_DIRS}")
  107. include_directories(${Boost_INCLUDE_DIRS})
  108. link_directories(${Boost_LIBRARY_DIRS})
  109. endif(Boost_FOUND)
  110. # Add Eigen to the included directories
  111. include_directories(${EIGEN3_INCLUDE_DIR})
  112. # Add GMMXX to the included directories
  113. include_directories(${GMMXX_INCLUDE_DIR})
  114. # Add the executables
  115. # Must be created *after* Boost was added because of LINK_DIRECTORIES
  116. add_executable(mrmc ${MRMC_SOURCES} ${MRMC_HEADERS})
  117. add_executable(mrmc-tests ${MRMC_TEST_SOURCES} ${MRMC_TEST_HEADERS})
  118. # Add target link deps for Boost program options
  119. target_link_libraries(mrmc ${Boost_LIBRARIES})
  120. target_link_libraries(mrmc-tests ${Boost_LIBRARIES})
  121. # Add a target to generate API documentation with Doxygen
  122. if(DOXYGEN_FOUND)
  123. set(CMAKE_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc")
  124. string(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${PROJECT_SOURCE_DIR}/src")
  125. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  126. add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMENT "Generating API documentation with Doxygen" VERBATIM)
  127. endif(DOXYGEN_FOUND)
  128. if (GTEST_INCLUDE_DIR)
  129. # For make-based builds, defines make target named test.
  130. # For Visual Studio builds, defines Visual Studio project named RUN_TESTS.
  131. enable_testing()
  132. include_directories(${GTEST_INCLUDE_DIR})
  133. target_link_libraries(mrmc-tests ${GTEST_LIBRARIES})
  134. add_test(NAME mrmc-tests COMMAND mrmc-tests)
  135. if(MSVC) # VS2012 doesn't support correctly the tuples yet
  136. add_definitions( /D _VARIADIC_MAX=10 )
  137. endif()
  138. endif(GTEST_INCLUDE_DIR)
  139. if (LOG4CPLUS_INCLUDE_DIR)
  140. include_directories(${LOG4CPLUS_INCLUDE_DIR})
  141. target_link_libraries(mrmc ${LOG4CPLUS_LIBRARIES})
  142. target_link_libraries(mrmc-tests ${LOG4CPLUS_LIBRARIES})
  143. # On Linux, we have to link against librt
  144. if (UNIX AND NOT APPLE)
  145. target_link_libraries(mrmc rt)
  146. target_link_libraries(mrmc-tests rt)
  147. endif(UNIX AND NOT APPLE)
  148. endif(LOG4CPLUS_INCLUDE_DIR)
  149. if (THREADS_FOUND)
  150. include_directories(${THREADS_INCLUDE_DIRS})
  151. target_link_libraries (mrmc ${CMAKE_THREAD_LIBS_INIT})
  152. target_link_libraries (mrmc-tests ${CMAKE_THREAD_LIBS_INIT})
  153. endif(THREADS_FOUND)
  154. # Configure a header file to pass some of the CMake settings to the source code
  155. configure_file (
  156. "${PROJECT_SOURCE_DIR}/mrmc-config.h.in"
  157. "${PROJECT_BINARY_DIR}/mrmc-config.h"
  158. )
  159. add_custom_target(memcheck valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/mrmc ${PROJECT_SOURCE_DIR}/examples/dtmc/crowds/crowds5_5.tra examples/dtmc/crowds/crowds5_5.lab
  160. DEPENDS mrmc)
  161. add_custom_target(memcheck-tests valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/mrmc-tests
  162. DEPENDS mrmc-tests)