CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # Author: Kang Lin <[email protected]>
  2. cmake_minimum_required(VERSION 3.16)
  3. project(coturn)
  4. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  5. set(CMAKE_C_STANDARD 11)
  6. set(CMAKE_C_STANDARD_REQUIRED ON)
  7. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
  8. # TODO: Modify this when the version is released
  9. SET(BUILD_VERSION "4.6.3")
  10. # Find Git Version Patch
  11. IF(EXISTS "${CMAKE_SOURCE_DIR}/.git")
  12. if(NOT GIT)
  13. SET(GIT $ENV{GIT})
  14. endif()
  15. if(NOT GIT)
  16. FIND_PROGRAM(GIT NAMES git git.exe git.cmd)
  17. endif()
  18. IF(GIT)
  19. EXECUTE_PROCESS(
  20. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  21. COMMAND ${GIT} describe --tags
  22. OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
  23. )
  24. if(NOT GIT_VERSION)
  25. EXECUTE_PROCESS(
  26. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  27. COMMAND ${GIT} rev-parse --short HEAD
  28. OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
  29. )
  30. endif()
  31. SET(BUILD_VERSION ${GIT_VERSION})
  32. ENDIF()
  33. ENDIF()
  34. string(FIND ${BUILD_VERSION} / BUILD_VERSION_POS REVERSE)
  35. if(BUILD_VERSION_POS GREATER -1)
  36. math(EXPR BUILD_VERSION_POS "${BUILD_VERSION_POS} + 1")
  37. string(SUBSTRING ${BUILD_VERSION} ${BUILD_VERSION_POS} -1 BUILD_VERSION)
  38. endif()
  39. message("BUILD_VERSION:${BUILD_VERSION};${_BUILD_VERSION}")
  40. set(VERSION ${BUILD_VERSION})
  41. if(NOT DEFINED CMAKE_BUILD_TYPE)
  42. set(CMAKE_BUILD_TYPE "Release")
  43. endif(NOT DEFINED CMAKE_BUILD_TYPE)
  44. string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
  45. if("debug" STREQUAL build_type)
  46. add_definitions(-D_DEBUG)
  47. endif()
  48. if(DEFINED TURN_SERVER_BUILD_INFO)
  49. add_definitions(-DTURN_SERVER_BUILD_INFO=${TURN_SERVER_BUILD_INFO})
  50. endif()
  51. IF(MSVC)
  52. # This option is to enable the /MP switch for Visual Studio 2005 and above compilers
  53. OPTION(WIN32_USE_MP "Set to ON to build with the /MP option (Visual Studio 2005 and above)." ON)
  54. MARK_AS_ADVANCED(WIN32_USE_MP)
  55. IF(WIN32_USE_MP)
  56. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  57. add_compile_options(/MP)
  58. ENDIF(WIN32_USE_MP)
  59. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
  60. add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
  61. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  62. ENDIF(MSVC)
  63. SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs")
  64. if (BUILD_SHARED_LIBS)
  65. add_definitions(-DBUILD_SHARED_LIBS)
  66. if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
  67. # Just setting CMAKE_POSITION_INDEPENDENT_CODE should be enough to set
  68. # -fPIC for GCC but sometimes it still doesn't get set, so make sure it
  69. # does.
  70. add_definitions("-fPIC")
  71. endif()
  72. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  73. endif(BUILD_SHARED_LIBS)
  74. include(CMakePackageConfigHelpers)
  75. include(GNUInstallDirs)
  76. include(GenerateExportHeader)
  77. include(CheckIncludeFile)
  78. include(CheckIncludeFileCXX)
  79. include(CheckFunctionExists)
  80. # Create will be delete files
  81. CONFIGURE_FILE(
  82. "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  83. "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
  84. IMMEDIATE @ONLY)
  85. # Create unistall target
  86. ADD_CUSTOM_TARGET(uninstall
  87. "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
  88. )
  89. add_subdirectory(src)
  90. CONFIGURE_FILE(
  91. "${CMAKE_SOURCE_DIR}/cmake/coturnConfig.cmake.in"
  92. "${CMAKE_BINARY_DIR}/coturnConfig.cmake"
  93. IMMEDIATE @ONLY)
  94. install(FILES "${CMAKE_BINARY_DIR}/coturnConfig.cmake"
  95. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/coturn"
  96. COMPONENT Development)
  97. install(DIRECTORY man DESTINATION .
  98. COMPONENT Runtime)
  99. install(DIRECTORY turndb/
  100. DESTINATION share/turnserver
  101. COMPONENT Runtime)
  102. install(DIRECTORY turndb/
  103. DESTINATION doc/turnserver
  104. COMPONENT Runtime)
  105. install(FILES
  106. LICENSE
  107. README.turnserver
  108. README.turnadmin
  109. README.turnutils
  110. INSTALL
  111. postinstall.txt
  112. DESTINATION doc/turnserver
  113. COMPONENT Runtime)
  114. install(FILES examples/etc/turnserver.conf
  115. DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
  116. COMPONENT Runtime
  117. RENAME turnserver.conf.default
  118. )
  119. install(DIRECTORY
  120. examples
  121. DESTINATION share
  122. COMPONENT examples
  123. )
  124. include(cmake/CMakeCPack.cmake)
  125. option(FUZZER "Build oss-fuzz fuzzing" OFF)
  126. if(FUZZER)
  127. if (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
  128. message(FATAL_ERROR "clang is require for libFuzzer")
  129. endif()
  130. add_subdirectory(fuzzing)
  131. endif()