CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Name of the project.
  2. # Language "C" is required for find_package(Threads).
  3. if (CMAKE_VERSION VERSION_LESS 3.0)
  4. project(srs CXX C)
  5. else()
  6. cmake_policy(SET CMP0048 NEW)
  7. project(srs VERSION 4.0.0 LANGUAGES CXX C)
  8. endif()
  9. cmake_minimum_required(VERSION 2.8.12)
  10. # For utest required C++11.
  11. set (CMAKE_CXX_STANDARD 11)
  12. ###########################################################
  13. execute_process(
  14. COMMAND bash -c "cd ${PROJECT_SOURCE_DIR}/../../ && pwd"
  15. OUTPUT_VARIABLE SRS_DIR
  16. )
  17. string(STRIP ${SRS_DIR} SRS_DIR)
  18. message("SRS home is ${SRS_DIR}")
  19. ###########################################################
  20. # Start to configure SRS with jobs of number of CPUs.
  21. include(ProcessorCount)
  22. ProcessorCount(JOBS)
  23. # We should always configure SRS for switching between branches.
  24. IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  25. EXECUTE_PROCESS(
  26. COMMAND ./configure --osx --srt=on --gb28181=on --apm=on --h265=on --hds=on --utest=on --ffmpeg-opus=off --jobs=${JOBS}
  27. WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
  28. ELSE ()
  29. EXECUTE_PROCESS(
  30. COMMAND ./configure --srt=on --gb28181=on --apm=on --h265=on --hds=on --utest=on --ffmpeg-opus=off --jobs=${JOBS}
  31. WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
  32. ENDIF ()
  33. if(NOT ret EQUAL 0)
  34. message(FATAL_ERROR "FAILED: ${ret}")
  35. endif()
  36. set(DEPS_LIBS ${SRS_DIR}/objs/st/libst.a
  37. ${SRS_DIR}/objs/openssl/lib/libssl.a
  38. ${SRS_DIR}/objs/openssl/lib/libcrypto.a
  39. ${SRS_DIR}/objs/srtp2/lib/libsrtp2.a
  40. ${SRS_DIR}/objs/ffmpeg/lib/libavcodec.a
  41. ${SRS_DIR}/objs/ffmpeg/lib/libavutil.a
  42. ${SRS_DIR}/objs/ffmpeg/lib/libswresample.a
  43. ${SRS_DIR}/objs/opus/lib/libopus.a
  44. ${SRS_DIR}/objs/srt/lib/libsrt.a)
  45. foreach(DEPS_LIB ${DEPS_LIBS})
  46. IF (NOT EXISTS ${DEPS_LIB})
  47. MESSAGE(FATAL_ERROR "${DEPS_LIB} not found")
  48. ELSE ()
  49. MESSAGE("${DEPS_LIB} is ok")
  50. ENDIF ()
  51. endforeach()
  52. ###########################################################
  53. # For whole project.
  54. INCLUDE_DIRECTORIES(${SRS_DIR}/objs
  55. ${SRS_DIR}/objs/st
  56. ${SRS_DIR}/objs/openssl/include
  57. ${SRS_DIR}/objs/srtp2/include
  58. ${SRS_DIR}/objs/ffmpeg/include
  59. ${SRS_DIR}/objs/srt/include
  60. ${SRS_DIR}/src/core
  61. ${SRS_DIR}/src/kernel
  62. ${SRS_DIR}/src/protocol
  63. ${SRS_DIR}/src/app
  64. ${SRS_DIR}/src/service)
  65. # Common used sources for SRS and utest.
  66. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/core SOURCE_FILES)
  67. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/kernel SOURCE_FILES)
  68. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/protocol SOURCE_FILES)
  69. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/app SOURCE_FILES)
  70. ADD_DEFINITIONS("-g -O0 -fsanitize=address -fno-omit-frame-pointer")
  71. ###########################################################
  72. # Setup SRS project
  73. set(SRS_SOURCE_FILES ${SOURCE_FILES})
  74. list(APPEND SRS_SOURCE_FILES ${SRS_DIR}/src/main/srs_main_server.cpp)
  75. ADD_EXECUTABLE(srs ${SRS_SOURCE_FILES})
  76. TARGET_LINK_LIBRARIES(srs dl)
  77. TARGET_LINK_LIBRARIES(srs ${DEPS_LIBS})
  78. TARGET_LINK_LIBRARIES(srs -ldl -pthread)
  79. TARGET_LINK_LIBRARIES(srs -rdynamic)
  80. TARGET_LINK_LIBRARIES(srs -fsanitize=address -fno-omit-frame-pointer)
  81. ###########################################################
  82. # For utest.
  83. # See https://google.github.io/googletest/quickstart-cmake.html
  84. # See https://stackoverflow.com/a/21479008/17679565
  85. ADD_SUBDIRECTORY(${SRS_DIR}/3rdparty/gtest-fit gtest-fit)
  86. INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
  87. INCLUDE_DIRECTORIES(${SRS_DIR}/src/utest)
  88. set(UTEST_SOURCE_FILES ${SOURCE_FILES})
  89. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/utest UTEST_SOURCE_FILES)
  90. ADD_EXECUTABLE(utest ${UTEST_SOURCE_FILES})
  91. TARGET_LINK_LIBRARIES(utest gtest gtest_main)
  92. TARGET_LINK_LIBRARIES(utest dl)
  93. TARGET_LINK_LIBRARIES(utest ${DEPS_LIBS})
  94. TARGET_LINK_LIBRARIES(utest -ldl -pthread)
  95. TARGET_LINK_LIBRARIES(utest -fsanitize=address -fno-omit-frame-pointer)
  96. ###########################################################
  97. # Done
  98. MESSAGE(STATUS "@see https://ossrs.net/lts/zh-cn/docs/v5/doc/ide")