CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. EXEC_PROGRAM("cd ${SRS_DIR} && ./configure --osx --srt=on --utest=on --jobs=${JOBS}")
  26. ELSE ()
  27. EXEC_PROGRAM("cd ${SRS_DIR} && ./configure --srt=on --utest=on --jobs=${JOBS}")
  28. ENDIF ()
  29. set(DEPS_LIBS ${SRS_DIR}/objs/st/libst.a
  30. ${SRS_DIR}/objs/openssl/lib/libssl.a
  31. ${SRS_DIR}/objs/openssl/lib/libcrypto.a
  32. ${SRS_DIR}/objs/srtp2/lib/libsrtp2.a
  33. ${SRS_DIR}/objs/ffmpeg/lib/libavcodec.a
  34. ${SRS_DIR}/objs/ffmpeg/lib/libavutil.a
  35. ${SRS_DIR}/objs/opus/lib/libopus.a
  36. ${SRS_DIR}/objs/ffmpeg/lib/libswresample.a
  37. ${SRS_DIR}/objs/srt/lib/libsrt.a)
  38. foreach(DEPS_LIB ${DEPS_LIBS})
  39. IF (NOT EXISTS ${DEPS_LIB})
  40. MESSAGE(FATAL_ERROR "${DEPS_LIB} not found")
  41. ELSE ()
  42. MESSAGE("${DEPS_LIB} is ok")
  43. ENDIF ()
  44. endforeach()
  45. ###########################################################
  46. # For whole project.
  47. INCLUDE_DIRECTORIES(${SRS_DIR}/objs
  48. ${SRS_DIR}/objs/st
  49. ${SRS_DIR}/objs/openssl/include
  50. ${SRS_DIR}/objs/srtp2/include
  51. ${SRS_DIR}/objs/opus/include
  52. ${SRS_DIR}/objs/ffmpeg/include
  53. ${SRS_DIR}/objs/srt/include
  54. ${SRS_DIR}/src/core
  55. ${SRS_DIR}/src/kernel
  56. ${SRS_DIR}/src/protocol
  57. ${SRS_DIR}/src/app
  58. ${SRS_DIR}/src/service
  59. ${SRS_DIR}/src/srt)
  60. # Common used sources for SRS and utest.
  61. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/core SOURCE_FILES)
  62. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/kernel SOURCE_FILES)
  63. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/protocol SOURCE_FILES)
  64. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/app SOURCE_FILES)
  65. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/srt SOURCE_FILES)
  66. # Remove the duplicated test main for srt.
  67. # TODO: FIMXE: Remove the file directly, use utest or main or research.
  68. list(REMOVE_ITEM SOURCE_FILES ${SRS_DIR}/src/srt/ts_demux_test.cpp)
  69. ADD_DEFINITIONS("-g -O0")
  70. ###########################################################
  71. # Setup SRS project
  72. set(SRS_SOURCE_FILES ${SOURCE_FILES})
  73. list(APPEND SRS_SOURCE_FILES ${SRS_DIR}/src/main/srs_main_server.cpp)
  74. ADD_EXECUTABLE(srs ${SRS_SOURCE_FILES})
  75. TARGET_LINK_LIBRARIES(srs dl)
  76. TARGET_LINK_LIBRARIES(srs ${DEPS_LIBS})
  77. TARGET_LINK_LIBRARIES(srs -ldl -pthread)
  78. ###########################################################
  79. # For utest.
  80. # See https://google.github.io/googletest/quickstart-cmake.html
  81. # See https://stackoverflow.com/a/21479008/17679565
  82. ADD_SUBDIRECTORY(${SRS_DIR}/3rdparty/gtest-fit gtest-fit)
  83. INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
  84. INCLUDE_DIRECTORIES(${SRS_DIR}/src/utest)
  85. set(UTEST_SOURCE_FILES ${SOURCE_FILES})
  86. AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/utest UTEST_SOURCE_FILES)
  87. ADD_EXECUTABLE(utest ${UTEST_SOURCE_FILES})
  88. TARGET_LINK_LIBRARIES(utest gtest gtest_main)
  89. TARGET_LINK_LIBRARIES(utest dl)
  90. TARGET_LINK_LIBRARIES(utest ${DEPS_LIBS})
  91. TARGET_LINK_LIBRARIES(utest -ldl -pthread)
  92. ###########################################################
  93. # Done
  94. MESSAGE(STATUS "@see https://github.com/ossrs/srs/wiki/v4_CN_IDE")