2
0

CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #.rst:
  2. # SgTests
  3. # -------
  4. #
  5. # Library testing.
  6. #
  7. # All library testings building.
  8. #
  9. # ::
  10. #
  11. # SG_TESTS_DIR - Directory containing the library tests.
  12. # SG_ANDROID_TESTS_DEST_DIR - Directory to send the library
  13. # tests (Android only).
  14. # SG_ANDROID_ADB_COMMAND - `adb` tool command line (Android only).
  15. # SG_TESTS - All available tests.
  16. # SG_TESTS_SOURCE - All available testing source.
  17. # SG_BUILD_<TEST>_TESTING - Enable/disable a <TEST> listed
  18. # by SG_TESTS, e.g: -DSG_BUILD_UTILS_TESTING=ON.
  19. # _
  20. # ___ __ _ __ _ _ _(_)
  21. # / __|/ _` |/ _` | | | | |
  22. # \__ \ (_| | (_| | |_| | |
  23. # |___/\__,_|\__, |\__,_|_|
  24. # |___/
  25. #
  26. # Cross-platform library which helps to develop web servers or frameworks.
  27. #
  28. # Copyright (C) 2016-2020 Silvio Clecio <[email protected]>
  29. #
  30. # Sagui library is free software; you can redistribute it and/or
  31. # modify it under the terms of the GNU Lesser General Public
  32. # License as published by the Free Software Foundation; either
  33. # version 2.1 of the License, or (at your option) any later version.
  34. #
  35. # Sagui library is distributed in the hope that it will be useful,
  36. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  38. # Lesser General Public License for more details.
  39. #
  40. # You should have received a copy of the GNU Lesser General Public
  41. # License along with Sagui library; if not, write to the Free Software
  42. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  43. #
  44. if(__SG_TESTS_INCLUDED)
  45. return()
  46. endif()
  47. set(__SG_TESTS_INCLUDED ON)
  48. if(BUILD_TESTING)
  49. add_definitions(-DSG_TESTING=1)
  50. if(WIN32)
  51. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  52. add_definitions(-DBINARY_DIR="${CMAKE_BINARY_DIR}")
  53. endif()
  54. if(CURL_VERSION_STRING AND CURL_LIBRARY)
  55. string(COMPARE GREATER_EQUAL ${CURL_VERSION_STRING} "7.56" _curl_found)
  56. else()
  57. unset(_curl_found)
  58. endif()
  59. set(SG_TESTS_DIR ${CMAKE_SOURCE_DIR}/test)
  60. if(ANDROID)
  61. find_program(SG_ANDROID_ADB_COMMAND adb)
  62. if(NOT SG_ANDROID_ADB_COMMAND)
  63. message(FATAL_ERROR "adb not found")
  64. endif()
  65. set(SG_ANDROID_TESTS_DEST_DIR "/data/local/tmp/sg_tests")
  66. add_definitions(-DSG_ANDROID_TESTS_DEST_DIR="${SG_ANDROID_TESTS_DEST_DIR}")
  67. endif()
  68. list(
  69. APPEND
  70. SG_TESTS
  71. utils
  72. extra
  73. str
  74. strmap
  75. httpauth
  76. httpuplds
  77. httpreq
  78. httpres
  79. httpsrv)
  80. if(SG_PATH_ROUTING)
  81. list(APPEND SG_TESTS entrypoint entrypoints routes router)
  82. endif()
  83. if(SG_MATH_EXPR_EVAL)
  84. list(APPEND SG_TESTS expr)
  85. endif()
  86. if(_curl_found)
  87. if(MINGW)
  88. list(APPEND _libs libcurl.a)
  89. else()
  90. add_definitions(-DCURL_STATICLIB=1)
  91. endif()
  92. list(APPEND SG_TESTS httpsrv_curl)
  93. if(SG_HTTPS_SUPPORT AND GNUTLS_FOUND)
  94. list(APPEND SG_TESTS httpsrv_tls_curl)
  95. endif()
  96. endif()
  97. set(SG_TESTS
  98. ${SG_TESTS}
  99. PARENT_SCOPE)
  100. list(APPEND _libs sagui)
  101. foreach(_test ${SG_TESTS})
  102. string(TOUPPER ${_test} _TEST)
  103. option(SG_BUILD_${_TEST}_TESTING "Build sg_${_test} testing" ON)
  104. if(SG_BUILD_${_TEST}_TESTING)
  105. list(APPEND SG_TESTS_SOURCE ${SG_TESTS_DIR}/test_${_test}.c)
  106. add_executable(test_${_test} ${SG_TESTS_DIR}/sg_assert.h
  107. ${SG_TESTS_DIR}/test_${_test}.c)
  108. target_link_libraries(test_${_test} ${_libs})
  109. if(_test MATCHES "curl")
  110. target_link_libraries(test_${_test} ${CURL_LIBRARIES} ${_libs})
  111. endif()
  112. target_include_directories(test_${_test} PUBLIC ${SG_SOURCE_DIR})
  113. if(ANDROID)
  114. add_custom_command(
  115. TARGET test_${_test}
  116. POST_BUILD
  117. COMMAND ${SG_ANDROID_ADB_COMMAND} shell mkdir -p
  118. ${SG_ANDROID_TESTS_DEST_DIR}
  119. COMMAND ${SG_ANDROID_ADB_COMMAND} push test_${_test}
  120. ${SG_ANDROID_TESTS_DEST_DIR})
  121. add_test(NAME test_${_test}
  122. COMMAND ${SG_ANDROID_ADB_COMMAND} shell
  123. ${SG_ANDROID_TESTS_DEST_DIR}/test_${_test})
  124. else()
  125. add_test(
  126. NAME test_${_test}
  127. WORKING_DIRECTORY ${SG_TESTS_DIR}
  128. COMMAND test_${_test})
  129. endif()
  130. endif()
  131. unset(_TEST)
  132. endforeach()
  133. unset(_curl_found)
  134. unset(_libs)
  135. if(ANDROID)
  136. add_custom_target(
  137. clean_pushed_tests
  138. COMMAND ${SG_ANDROID_ADB_COMMAND} shell rm -rf
  139. ${SG_ANDROID_TESTS_DEST_DIR}
  140. COMMENT "Cleaning all pushed tests"
  141. VERBATIM)
  142. endif()
  143. set(SG_TESTS_SOURCE
  144. ${SG_TESTS_SOURCE}
  145. PARENT_SCOPE)
  146. endif()