CMakeLists.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #.rst:
  2. # SgLibrary
  3. # ---------
  4. #
  5. # Main library building.
  6. #
  7. # The main building of the Sagui library. It includes all necessary sub-building
  8. # scripts to manage the library building.
  9. #
  10. # ::
  11. #
  12. # SG_INCLUDE_DIR - Directory containing the library header.
  13. # SG_USE_OUTPUT_PREFIX - Install all files into "./Output" directory.
  14. # _
  15. # ___ __ _ __ _ _ _(_)
  16. # / __|/ _` |/ _` | | | | |
  17. # \__ \ (_| | (_| | |_| | |
  18. # |___/\__,_|\__, |\__,_|_|
  19. # |___/
  20. #
  21. # Cross-platform library which helps to develop web servers or frameworks.
  22. #
  23. # Copyright (C) 2016-2020 Silvio Clecio <[email protected]>
  24. #
  25. # Sagui library is free software; you can redistribute it and/or
  26. # modify it under the terms of the GNU Lesser General Public
  27. # License as published by the Free Software Foundation; either
  28. # version 2.1 of the License, or (at your option) any later version.
  29. #
  30. # Sagui library is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  33. # Lesser General Public License for more details.
  34. #
  35. # You should have received a copy of the GNU Lesser General Public
  36. # License along with Sagui library; if not, write to the Free Software
  37. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  38. #
  39. cmake_minimum_required(VERSION 3.0.2)
  40. project(sagui C)
  41. set(CMAKE_C_STANDARD 99)
  42. set(PROJECT_DESCRIPTION
  43. "Cross-platform library which helps to develop web servers or frameworks.")
  44. set(PROJECT_VENDOR "The Sagui Library Development Team")
  45. set(PROJECT_URL "https://github.com/risoflora/libsagui")
  46. set(PROJECT_ISSUES_URL "${PROJECT_URL}/issues")
  47. set(SG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
  48. if(NOT CMAKE_BUILD_TYPE)
  49. set(CMAKE_BUILD_TYPE Release)
  50. endif()
  51. if(NOT DEFINED BUILD_SHARED_LIBS)
  52. set(BUILD_SHARED_LIBS ON)
  53. endif()
  54. if((SG_USE_OUTPUT_PREFIX OR MINGW)
  55. AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  56. set(CMAKE_INSTALL_PREFIX
  57. "${CMAKE_BINARY_DIR}/Output"
  58. CACHE PATH "..." FORCE)
  59. endif()
  60. # Based on: https://gitlab.kitware.com/cmake/cmake/issues/19460
  61. if(DEFINED CMAKE_OSX_SYSROOT)
  62. set(CC "CC=${CMAKE_C_COMPILER} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}")
  63. else()
  64. set(CC "CC=${CMAKE_C_COMPILER}")
  65. endif()
  66. if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
  67. set(CMAKE_COMPILER_IS_CLANG ON)
  68. endif()
  69. if(NOT CMAKE_C_MACHINE)
  70. execute_process(
  71. COMMAND ${CMAKE_C_COMPILER} -dumpmachine
  72. OUTPUT_VARIABLE _machine
  73. RESULT_VARIABLE _result
  74. OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  75. if(_result EQUAL 0)
  76. set(CMAKE_C_MACHINE "${_machine}") # the machine which building for
  77. endif()
  78. unset(_machine)
  79. unset(_result)
  80. endif()
  81. set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
  82. option(SG_HTTPS_SUPPORT "Enable HTTPS support" OFF)
  83. option(SG_HTTP_COMPRESSION "Enable HTTP compression" ON)
  84. option(SG_PATH_ROUTING "Enable path routing" ON)
  85. option(SG_MATH_EXPR_EVAL "Enable mathematical expression evaluator" ON)
  86. include(GNUInstallDirs)
  87. include(ExternalProject)
  88. include(SgFlags)
  89. include(SgGNUSource)
  90. include(SgVersion)
  91. include(SgABIComplianceChecker)
  92. if(SG_HTTPS_SUPPORT)
  93. include(FindGnuTLS)
  94. if(GNUTLS_FOUND)
  95. add_definitions(-DSG_HTTPS_SUPPORT=1)
  96. if(MINGW)
  97. get_filename_component(_ext ${GNUTLS_LIBRARIES} EXT)
  98. if(_ext MATCHES ".dll.a")
  99. unset(_ext)
  100. get_filename_component(_ori_path ${GNUTLS_LIBRARIES} PATH)
  101. string(REGEX REPLACE "lib$" "bin" _path "${_ori_path}")
  102. unset(_ori_path)
  103. get_filename_component(_name ${GNUTLS_LIBRARIES} NAME_WE)
  104. string(CONCAT _basename ${_path} "/" ${_name} "-")
  105. unset(_path)
  106. unset(_name)
  107. string(CONCAT _fullname ${_basename} "20.dll")
  108. if(NOT ${_fullname})
  109. string(CONCAT _fullname ${_basename} "30.dll")
  110. endif()
  111. set(GNUTLS_LIBRARIES
  112. "${_fullname}"
  113. CACHE STRING "The libraries needed to use gnutls" FORCE)
  114. unset(_fullname)
  115. endif()
  116. endif()
  117. endif()
  118. endif()
  119. include(SgMHD)
  120. if(SG_HTTP_COMPRESSION)
  121. include(SgZLib)
  122. add_definitions(-DSG_HTTP_COMPRESSION=1)
  123. endif()
  124. if(SG_PATH_ROUTING)
  125. include(SgPCRE2)
  126. add_definitions(-DSG_PATH_ROUTING=1)
  127. endif()
  128. if(SG_MATH_EXPR_EVAL)
  129. add_definitions(-DSG_MATH_EXPR_EVAL=1)
  130. endif()
  131. if(WIN32 AND BUILD_SHARED_LIBS)
  132. include(SgRC)
  133. endif()
  134. include(SgPC)
  135. include(SgUninstall)
  136. if(BUILD_TESTING)
  137. if(CMAKE_BUILD_TYPE MATCHES "[Dd]ebug|DEBUG")
  138. include(FindCURL)
  139. add_definitions(-DBUILD_TESTING=1)
  140. enable_testing()
  141. else()
  142. set(BUILD_TESTING OFF)
  143. message(STATUS "BUILD_TESTING disabled in build type ${CMAKE_BUILD_TYPE}")
  144. endif()
  145. endif()
  146. if(UNIX AND ((NOT APPLE) AND (NOT ANDROID)))
  147. include(CheckIncludeFiles)
  148. check_include_files(errno.h HAVE_ERRNO_H)
  149. if(NOT HAVE_ERRNO_H)
  150. include_directories(/usr/include/asm-generic)
  151. endif()
  152. endif()
  153. if(MINGW)
  154. message(STATUS "Looking for inet_ntop")
  155. set(_chk_inet_ntop_src "${CMAKE_BINARY_DIR}/check_inet_ntop.c")
  156. file(
  157. WRITE ${_chk_inet_ntop_src}
  158. "#include <stdio.h>\n#include <ws2tcpip.h>\nint main(void){inet_ntop(0,NULL,NULL,0);return 0;}"
  159. )
  160. try_compile(HAVE_INET_NTOP ${CMAKE_BINARY_DIR} ${_chk_inet_ntop_src}
  161. LINK_LIBRARIES ws2_32)
  162. file(REMOVE ${_chk_inet_ntop_src})
  163. unset(_chk_inet_ntop_src)
  164. if(${HAVE_INET_NTOP})
  165. message(STATUS "Looking for inet_ntop - found")
  166. else()
  167. message(STATUS "Looking for inet_ntop - not found")
  168. endif()
  169. else()
  170. include(CheckIncludeFile)
  171. check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
  172. if(HAVE_ARPA_INET_H)
  173. add_definitions(-DHAVE_ARPA_INET_H=1)
  174. endif()
  175. include(CheckFunctionExists)
  176. check_function_exists(inet_ntop HAVE_INET_NTOP)
  177. if(NOT HAVE_INET_NTOP)
  178. include(CheckSymbolExists)
  179. check_symbol_exists(inet_ntop "arpa/inet.h" HAVE_INET_NTOP)
  180. endif()
  181. endif()
  182. if(${HAVE_INET_NTOP})
  183. add_definitions(-DHAVE_INET_NTOP=1)
  184. endif()
  185. include_directories(${SG_INCLUDE_DIR})
  186. include_directories(${MHD_INCLUDE_DIR})
  187. if(SG_HTTP_COMPRESSION)
  188. include_directories(${ZLIB_INCLUDE_DIR})
  189. endif()
  190. if(SG_PATH_ROUTING)
  191. include_directories(${PCRE2_INCLUDE_DIR})
  192. endif()
  193. add_subdirectory(src)
  194. add_subdirectory(examples)
  195. add_subdirectory(test)
  196. include(SgDoxygen)
  197. include(SgSummary)
  198. include(SgCPack)
  199. include(SgPVSStudio)