CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #.rst:
  2. # SgExamples
  3. # ----------
  4. #
  5. # Library examples.
  6. #
  7. # All library examples building.
  8. #
  9. # ::
  10. #
  11. # SG_EXAMPLES_SOURCE_DIR - Directory containing the library examples.
  12. # SG_EXAMPLES_CERTS_DIR - Directory containing the example certificates
  13. # if -DSG_HTTPS_SUPPORT=ON.
  14. # SG_EXAMPLES - All available examples.
  15. # SG_EXAMPLES_SOURCE - All available example source.
  16. # SG_BUILD_<EXAMPLE>_EXAMPLE - Enable/disable a <SG_EXAMPLE> listed
  17. # by SG_EXAMPLES, e.g: -DSG_BUILD_STR_EXAMPLE=ON.
  18. # _
  19. # ___ __ _ __ _ _ _(_)
  20. # / __|/ _` |/ _` | | | | |
  21. # \__ \ (_| | (_| | |_| | |
  22. # |___/\__,_|\__, |\__,_|_|
  23. # |___/
  24. #
  25. # Cross-platform library which helps to develop web servers or frameworks.
  26. #
  27. # Copyright (C) 2016-2020 Silvio Clecio <[email protected]>
  28. #
  29. # Sagui library is free software; you can redistribute it and/or
  30. # modify it under the terms of the GNU Lesser General Public
  31. # License as published by the Free Software Foundation; either
  32. # version 2.1 of the License, or (at your option) any later version.
  33. #
  34. # Sagui library is distributed in the hope that it will be useful,
  35. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  37. # Lesser General Public License for more details.
  38. #
  39. # You should have received a copy of the GNU Lesser General Public
  40. # License along with Sagui library; if not, write to the Free Software
  41. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  42. #
  43. if(__SG_EXAMPLES_INCLUDED)
  44. return()
  45. endif()
  46. set(__SG_EXAMPLES_INCLUDED ON)
  47. option(SG_BUILD_EXAMPLES "Enable the library examples building" ON)
  48. if(SG_BUILD_EXAMPLES)
  49. if(WIN32)
  50. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  51. endif()
  52. set(SG_EXAMPLES_SOURCE_DIR ${CMAKE_SOURCE_DIR}/examples)
  53. list(
  54. APPEND
  55. SG_EXAMPLES
  56. str
  57. strmap
  58. httpauth
  59. httpcookie
  60. httpsrv
  61. httpuplds
  62. httpsrv_benchmark
  63. httpsrv_sse
  64. httpreq_form
  65. httpreq_payload
  66. httpreq_isolate)
  67. if(SG_HTTPS_SUPPORT AND GNUTLS_FOUND)
  68. set(SG_EXAMPLES_CERTS_DIR "${SG_EXAMPLES_SOURCE_DIR}/certs")
  69. add_definitions(-DSG_EXAMPLES_CERTS_DIR="${SG_EXAMPLES_CERTS_DIR}")
  70. list(APPEND SG_EXAMPLES httpsrv_tls)
  71. list(APPEND SG_EXAMPLES httpsrv_tls_cert_auth)
  72. endif()
  73. if(SG_HTTP_COMPRESSION)
  74. list(APPEND SG_EXAMPLES httpcomp)
  75. endif()
  76. if(SG_PATH_ROUTING)
  77. list(
  78. APPEND
  79. SG_EXAMPLES
  80. entrypoint
  81. router_simple
  82. router_segments
  83. router_vars
  84. router_srv)
  85. endif()
  86. if(SG_MATH_EXPR_EVAL)
  87. list(APPEND SG_EXAMPLES expr_basic)
  88. list(APPEND SG_EXAMPLES expr_full)
  89. endif()
  90. set(SG_EXAMPLES
  91. ${SG_EXAMPLES}
  92. PARENT_SCOPE)
  93. list(APPEND _libs sagui)
  94. foreach(_example ${SG_EXAMPLES})
  95. string(TOUPPER ${_example} _EXAMPLE)
  96. option(SG_BUILD_${_EXAMPLE}_EXAMPLE "Build sg_${_example} example" ON)
  97. if(SG_BUILD_${_EXAMPLE}_EXAMPLE)
  98. list(APPEND SG_EXAMPLES_SOURCE
  99. ${SG_EXAMPLES_SOURCE_DIR}/example_${_example}.c)
  100. add_executable(example_${_example}
  101. ${SG_EXAMPLES_SOURCE_DIR}/example_${_example}.c)
  102. target_link_libraries(example_${_example} ${_libs})
  103. endif()
  104. unset(_EXAMPLE)
  105. endforeach()
  106. unset(_libs)
  107. set(SG_EXAMPLES_SOURCE
  108. ${SG_EXAMPLES_SOURCE}
  109. PARENT_SCOPE)
  110. endif()