CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Name of the project.
  2. # Language "C" is required for find_package(Threads).
  3. if (CMAKE_VERSION VERSION_LESS 3.0)
  4. project(st CXX C ASM)
  5. else()
  6. cmake_policy(SET CMP0048 NEW)
  7. project(st VERSION 4.0.0 LANGUAGES CXX C ASM)
  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 ST_DIR
  16. )
  17. string(STRIP ${ST_DIR} ST_DIR)
  18. message("ST home is ${ST_DIR}")
  19. ###########################################################
  20. # Start to configure ST with jobs of number of CPUs.
  21. include(ProcessorCount)
  22. ProcessorCount(JOBS)
  23. # We should always configure ST for switching between branches.
  24. IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  25. ADD_DEFINITIONS("-arch x86_64 -DDARWIN -DMD_HAVE_KQUEUE -DMD_HAVE_SELECT -DDEBUG")
  26. ELSE ()
  27. ADD_DEFINITIONS("-DLINUX -DMD_HAVE_EPOLL -DMD_HAVE_SELECT -DDEBUG")
  28. ENDIF ()
  29. EXEC_PROGRAM("cd ${ST_DIR} && mkdir -p obj && cp public.h obj/st.h")
  30. ###########################################################
  31. # For whole project.
  32. INCLUDE_DIRECTORIES(${ST_DIR}/obj ${ST_DIR}/utest ${ST_DIR}/utest/gtest/include)
  33. # Common used sources for SRS and utest.
  34. list(APPEND SOURCE_FILES ${ST_DIR}/event.c)
  35. list(APPEND SOURCE_FILES ${ST_DIR}/io.c)
  36. list(APPEND SOURCE_FILES ${ST_DIR}/key.c)
  37. list(APPEND SOURCE_FILES ${ST_DIR}/sched.c)
  38. list(APPEND SOURCE_FILES ${ST_DIR}/stk.c)
  39. list(APPEND SOURCE_FILES ${ST_DIR}/sync.c)
  40. IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  41. list(APPEND SOURCE_FILES ${ST_DIR}/md_darwin.S)
  42. ELSE ()
  43. list(APPEND SOURCE_FILES ${ST_DIR}/md_linux.S)
  44. list(APPEND SOURCE_FILES ${ST_DIR}/md_linux2.S)
  45. ENDIF ()
  46. ADD_DEFINITIONS("-g -O0")
  47. ###########################################################
  48. # Setup ST utest project
  49. ADD_SUBDIRECTORY(${ST_DIR}/utest/gtest-fit gtest-fit)
  50. INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
  51. set(ST_UTEST_SOURCE_FILES ${SOURCE_FILES})
  52. AUX_SOURCE_DIRECTORY(${ST_DIR}/utest ST_UTEST_SOURCE_FILES)
  53. ADD_EXECUTABLE(st_utest ${ST_UTEST_SOURCE_FILES})
  54. TARGET_LINK_LIBRARIES(st_utest gtest gtest_main)
  55. TARGET_LINK_LIBRARIES(st_utest dl)
  56. TARGET_LINK_LIBRARIES(st_utest ${DEPS_LIBS})
  57. TARGET_LINK_LIBRARIES(st_utest -ldl -pthread)
  58. ###########################################################
  59. # Setup tools/backtrace project
  60. set(ST_BACKTRACE_SOURCE_FILES ${SOURCE_FILES})
  61. AUX_SOURCE_DIRECTORY(${ST_DIR}/tools/backtrace ST_BACKTRACE_SOURCE_FILES)
  62. ADD_EXECUTABLE(st_backtrace ${ST_BACKTRACE_SOURCE_FILES})
  63. TARGET_LINK_LIBRARIES(st_backtrace ${DEPS_LIBS})
  64. TARGET_LINK_LIBRARIES(st_backtrace -ldl)
  65. ###########################################################
  66. # Setup tools/helloworld project
  67. set(ST_HELLOWORLD_SOURCE_FILES ${SOURCE_FILES})
  68. AUX_SOURCE_DIRECTORY(${ST_DIR}/tools/helloworld ST_HELLOWORLD_SOURCE_FILES)
  69. ADD_EXECUTABLE(st_helloworld ${ST_HELLOWORLD_SOURCE_FILES})
  70. TARGET_LINK_LIBRARIES(st_helloworld ${DEPS_LIBS})
  71. ###########################################################
  72. # Setup tools/jmpbuf project
  73. set(ST_JMPBUF_SOURCE_FILES ${SOURCE_FILES})
  74. AUX_SOURCE_DIRECTORY(${ST_DIR}/tools/jmpbuf ST_JMPBUF_SOURCE_FILES)
  75. ADD_EXECUTABLE(st_jmpbuf ${ST_JMPBUF_SOURCE_FILES})
  76. TARGET_LINK_LIBRARIES(st_jmpbuf ${DEPS_LIBS})
  77. ###########################################################
  78. # Setup tools/pcs project
  79. set(ST_PCS_SOURCE_FILES ${SOURCE_FILES})
  80. AUX_SOURCE_DIRECTORY(${ST_DIR}/tools/pcs ST_PCS_SOURCE_FILES)
  81. ADD_EXECUTABLE(st_pcs ${ST_PCS_SOURCE_FILES})
  82. TARGET_LINK_LIBRARIES(st_pcs ${DEPS_LIBS})
  83. ###########################################################
  84. # Setup tools/porting project
  85. set(ST_PORTING_SOURCE_FILES ${SOURCE_FILES})
  86. AUX_SOURCE_DIRECTORY(${ST_DIR}/tools/porting ST_PORTING_SOURCE_FILES)
  87. ADD_EXECUTABLE(st_porting ${ST_PORTING_SOURCE_FILES})
  88. TARGET_LINK_LIBRARIES(st_porting ${DEPS_LIBS})
  89. ###########################################################
  90. # Setup tools/stack project
  91. set(ST_STACK_SOURCE_FILES ${SOURCE_FILES})
  92. AUX_SOURCE_DIRECTORY(${ST_DIR}/tools/stack ST_STACK_SOURCE_FILES)
  93. ADD_EXECUTABLE(st_stack ${ST_STACK_SOURCE_FILES})
  94. TARGET_LINK_LIBRARIES(st_stack ${DEPS_LIBS})
  95. ###########################################################
  96. # Setup tools/verify project
  97. set(ST_VERIFY_SOURCE_FILES ${SOURCE_FILES})
  98. AUX_SOURCE_DIRECTORY(${ST_DIR}/tools/verify ST_VERIFY_SOURCE_FILES)
  99. ADD_EXECUTABLE(st_verify ${ST_VERIFY_SOURCE_FILES})
  100. TARGET_LINK_LIBRARIES(st_verify ${DEPS_LIBS})
  101. ###########################################################
  102. # Done
  103. MESSAGE(STATUS "@see https://github.com/ossrs/state-threads#usage")