CMakeLists.txt 4.4 KB

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