CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ##
  2. # SPDX-License-Identifier: BSD-3-Clause
  3. #
  4. # https://opensource.org/license/bsd-3-clause
  5. #
  6. # Copyright (C) 2021 Kang Lin <[email protected]>
  7. #
  8. # All rights reserved.
  9. #
  10. # Redistribution and use in source and binary forms, with or without
  11. # modification, are permitted provided that the following conditions
  12. # are met:
  13. # 1. Redistributions of source code must retain the above copyright
  14. # notice, this list of conditions and the following disclaimer.
  15. # 2. Redistributions in binary form must reproduce the above copyright
  16. # notice, this list of conditions and the following disclaimer in the
  17. # documentation and/or other materials provided with the distribution.
  18. # 3. Neither the name of the project nor the names of its contributors
  19. # may be used to endorse or promote products derived from this software
  20. # without specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  23. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  26. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. # SUCH DAMAGE.
  33. ##
  34. cmake_minimum_required(VERSION 3.16)
  35. project(coturn)
  36. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  37. set(CMAKE_C_STANDARD 11)
  38. set(CMAKE_C_STANDARD_REQUIRED ON)
  39. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
  40. # TODO: Modify this when the version is released
  41. SET(BUILD_VERSION "4.7.0")
  42. # Find Git Version Patch
  43. IF(EXISTS "${CMAKE_SOURCE_DIR}/.git")
  44. if(NOT GIT)
  45. SET(GIT $ENV{GIT})
  46. endif()
  47. if(NOT GIT)
  48. FIND_PROGRAM(GIT NAMES git git.exe git.cmd)
  49. endif()
  50. IF(GIT)
  51. EXECUTE_PROCESS(
  52. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  53. COMMAND ${GIT} describe --tags
  54. OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
  55. )
  56. if(NOT GIT_VERSION)
  57. EXECUTE_PROCESS(
  58. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  59. COMMAND ${GIT} rev-parse --short HEAD
  60. OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
  61. )
  62. endif()
  63. SET(BUILD_VERSION ${GIT_VERSION})
  64. ENDIF()
  65. ENDIF()
  66. string(FIND ${BUILD_VERSION} / BUILD_VERSION_POS REVERSE)
  67. if(BUILD_VERSION_POS GREATER -1)
  68. math(EXPR BUILD_VERSION_POS "${BUILD_VERSION_POS} + 1")
  69. string(SUBSTRING ${BUILD_VERSION} ${BUILD_VERSION_POS} -1 BUILD_VERSION)
  70. endif()
  71. message("BUILD_VERSION:${BUILD_VERSION};${_BUILD_VERSION}")
  72. set(VERSION ${BUILD_VERSION})
  73. if(NOT DEFINED CMAKE_BUILD_TYPE)
  74. set(CMAKE_BUILD_TYPE "Release")
  75. endif(NOT DEFINED CMAKE_BUILD_TYPE)
  76. string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
  77. if("debug" STREQUAL build_type)
  78. add_definitions(-D_DEBUG)
  79. endif()
  80. if(DEFINED TURN_SERVER_BUILD_INFO)
  81. add_definitions(-DTURN_SERVER_BUILD_INFO=${TURN_SERVER_BUILD_INFO})
  82. endif()
  83. IF(MSVC)
  84. # This option is to enable the /MP switch for Visual Studio 2005 and above compilers
  85. OPTION(WIN32_USE_MP "Set to ON to build with the /MP option (Visual Studio 2005 and above)." ON)
  86. MARK_AS_ADVANCED(WIN32_USE_MP)
  87. IF(WIN32_USE_MP)
  88. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  89. add_compile_options(/MP)
  90. ENDIF(WIN32_USE_MP)
  91. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
  92. add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
  93. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  94. ENDIF(MSVC)
  95. SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs")
  96. if (BUILD_SHARED_LIBS)
  97. add_definitions(-DBUILD_SHARED_LIBS)
  98. if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
  99. # Just setting CMAKE_POSITION_INDEPENDENT_CODE should be enough to set
  100. # -fPIC for GCC but sometimes it still doesn't get set, so make sure it
  101. # does.
  102. add_definitions("-fPIC")
  103. endif()
  104. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  105. endif(BUILD_SHARED_LIBS)
  106. # Uncomment to disable OAuth support
  107. #add_definitions(-DTURN_NO_OAUTH)
  108. include(CMakePackageConfigHelpers)
  109. include(GNUInstallDirs)
  110. include(GenerateExportHeader)
  111. include(CheckIncludeFile)
  112. include(CheckIncludeFileCXX)
  113. include(CheckFunctionExists)
  114. # Create will be delete files
  115. CONFIGURE_FILE(
  116. "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  117. "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
  118. IMMEDIATE @ONLY)
  119. # Create unistall target
  120. ADD_CUSTOM_TARGET(uninstall
  121. "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
  122. )
  123. add_subdirectory(src)
  124. CONFIGURE_FILE(
  125. "${CMAKE_SOURCE_DIR}/cmake/coturnConfig.cmake.in"
  126. "${CMAKE_BINARY_DIR}/coturnConfig.cmake"
  127. IMMEDIATE @ONLY)
  128. install(FILES "${CMAKE_BINARY_DIR}/coturnConfig.cmake"
  129. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/coturn"
  130. COMPONENT Development)
  131. install(DIRECTORY man DESTINATION .
  132. COMPONENT Runtime)
  133. install(DIRECTORY turndb/
  134. DESTINATION share/turnserver
  135. COMPONENT Runtime)
  136. install(DIRECTORY turndb/
  137. DESTINATION doc/turnserver
  138. COMPONENT Runtime)
  139. install(FILES
  140. LICENSE
  141. README.turnserver
  142. README.turnadmin
  143. README.turnutils
  144. INSTALL
  145. postinstall.txt
  146. DESTINATION doc/turnserver
  147. COMPONENT Runtime)
  148. install(FILES examples/etc/turnserver.conf
  149. DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
  150. COMPONENT Runtime
  151. RENAME turnserver.conf.default
  152. )
  153. install(DIRECTORY
  154. examples
  155. DESTINATION share
  156. COMPONENT examples
  157. )
  158. include(cmake/CMakeCPack.cmake)
  159. option(FUZZER "Build oss-fuzz fuzzing" OFF)
  160. if(FUZZER)
  161. if (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
  162. message(FATAL_ERROR "clang is require for libFuzzer")
  163. endif()
  164. add_subdirectory(fuzzing)
  165. endif()