CMakeLists.txt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # ----------------------------------------------------------------------------
  2. # Root CMake file for CNStream
  3. # ----------------------------------------------------------------------------
  4. # Disable in-source builds to prevent source tree corruption.
  5. if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
  6. message(FATAL_ERROR "Please create a separate directory for build files.")
  7. endif()
  8. cmake_minimum_required(VERSION 2.8.7)
  9. if(POLICY CMP0046)
  10. cmake_policy(SET CMP0046 NEW)
  11. endif()
  12. if(POLICY CMP0054)
  13. cmake_policy(SET CMP0054 NEW)
  14. endif()
  15. # ---[ CNStream project
  16. project(CNStream C CXX)
  17. set(CMAKE_VERBOSE_MAKEFILE OFF)
  18. # ---[ Options
  19. option(build_modules "build modules" ON)
  20. option(build_modules_contrib "build extra modules" OFF)
  21. option(build_source "build source programs" ON)
  22. option(build_tests "build unit tests" ON)
  23. option(build_test_coverage "Test code coverage" OFF)
  24. option(build_tools "build tools" ON)
  25. option(build_python_api "build python api" OFF)
  26. # To use sanitizers, the version of GCC is required to be no less than 4.9
  27. option(SANITIZE_MEMORY "Enable MemorySanitizer for sanitized targets." OFF)
  28. option(SANITIZE_ADDRESS "Enable AddressSanitizer for sanitized targets." OFF)
  29. option(SANITIZE_THREAD "Enable ThreadSanitizer for sanitized targets." OFF)
  30. option(SANITIZE_UNDEFINED "Enable UndefinedBehaviorSanitizer for sanitized targets." OFF)
  31. # ---[ Build Flags
  32. if(USE_libstdcpp)
  33. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
  34. message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
  35. endif()
  36. if(build_test_coverage)
  37. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
  38. endif()
  39. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath=.")
  40. if(build_tests)
  41. # ---[ gtest
  42. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/googletest)
  43. set(build_gtest_already ON) # used by subdirectories
  44. endif()
  45. # ---[ build
  46. add_subdirectory(framework)
  47. if(build_modules OR build_tools)
  48. set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/easydk/lib)
  49. add_subdirectory(easydk)
  50. endif()
  51. if(build_modules)
  52. add_subdirectory(modules)
  53. endif()
  54. if(build_modules_contrib)
  55. add_subdirectory(modules_contrib)
  56. endif()
  57. if(build_source)
  58. add_subdirectory(source)
  59. endif()
  60. if(build_tools)
  61. add_subdirectory(tools)
  62. endif()
  63. if(build_python_api)
  64. add_subdirectory(python)
  65. endif()
  66. # ---[ install
  67. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") #set runtime path
  68. if(INSTALL_SOURCE)
  69. install(DIRECTORY easydk DESTINATION . USE_SOURCE_PERMISSIONS
  70. PATTERN "easydk/lib" EXCLUDE)
  71. endif()