CMakeLists.txt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. cmake_minimum_required(VERSION 2.8.7)
  2. if(POLICY CMP0046)
  3. cmake_policy(SET CMP0046 NEW)
  4. endif()
  5. if(POLICY CMP0054)
  6. cmake_policy(SET CMP0054 NEW)
  7. endif()
  8. include(CheckCXXCompilerFlag)
  9. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  10. if(NOT COMPILER_SUPPORTS_CXX11)
  11. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  12. endif()
  13. # compile flags
  14. set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
  15. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
  16. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
  17. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
  18. set(CNSTREAM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
  19. set(LIBRARY_OUTPUT_PATH ${CNSTREAM_ROOT_DIR}/lib)
  20. set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/)
  21. set(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake)
  22. # ---[ neuware
  23. find_package(Neuware)
  24. include_directories(${NEUWARE_INCLUDE_DIR})
  25. # ---[ Google-gflags
  26. include(${CNSTREAM_ROOT_DIR}/cmake/FindGFlags.cmake)
  27. include_directories(${GFLAGS_INCLUDE_DIRS})
  28. # ---[ rapidjson
  29. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/rapidjson/include)
  30. set(VERSION_HEAD_FILE ${CMAKE_CURRENT_SOURCE_DIR}/core/include/cnstream_version.hpp)
  31. execute_process(COMMAND awk /CNSTREAM_MAJOR_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
  32. string(REGEX MATCH "[0-9]+" MAJOR_VERSION ${VERSION_STR})
  33. execute_process(COMMAND awk /CNSTREAM_MINOR_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
  34. string(REGEX MATCH "[0-9]+" MINOR_VERSION ${VERSION_STR})
  35. execute_process(COMMAND awk /CNSTREAM_PATCH_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
  36. string(REGEX MATCH "[0-9]+" PATCH_VERSION ${VERSION_STR})
  37. set(CNSTREAM_TARGET_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
  38. # ---[ source
  39. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/core/include)
  40. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/core/src core_srcs)
  41. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/core/src/profiler profiler_srcs)
  42. if(build_tests)
  43. add_definitions(-DUNIT_TEST)
  44. endif()
  45. add_library(cnstream_core SHARED ${core_srcs} ${profiler_srcs})
  46. target_link_libraries(cnstream_core dl pthread ${CNRT_LIBS} ${GFLAGS_LIBRARIES})
  47. set_target_properties(cnstream_core PROPERTIES LINK_FLAGS_RELEASE -s)
  48. set_target_properties(cnstream_core PROPERTIES VERSION ${CNSTREAM_TARGET_VERSION})
  49. # install
  50. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") #set runtime path
  51. install(TARGETS cnstream_core LIBRARY DESTINATION lib)
  52. install(DIRECTORY core/include/ DESTINATION include)
  53. if(build_tests)
  54. add_subdirectory(unitest)
  55. endif()