Macros.cmake 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.haxx.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. ###########################################################################
  22. #File defines convenience macros for available feature testing
  23. # This macro checks if the symbol exists in the library and if it
  24. # does, it prepends library to the list. It is intended to be called
  25. # multiple times with a sequence of possibly dependent libraries in
  26. # order of least-to-most-dependent. Some libraries depend on others
  27. # to link correctly.
  28. macro(check_library_exists_concat LIBRARY SYMBOL VARIABLE)
  29. check_library_exists("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "${CMAKE_LIBRARY_PATH}"
  30. ${VARIABLE})
  31. if(${VARIABLE})
  32. set(CURL_LIBS ${LIBRARY} ${CURL_LIBS})
  33. endif()
  34. endmacro()
  35. # Check if header file exists and add it to the list.
  36. # This macro is intended to be called multiple times with a sequence of
  37. # possibly dependent header files. Some headers depend on others to be
  38. # compiled correctly.
  39. macro(check_include_file_concat FILE VARIABLE)
  40. check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
  41. if(${VARIABLE})
  42. set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
  43. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
  44. endif()
  45. endmacro()
  46. # For other curl specific tests, use this macro.
  47. macro(curl_internal_test CURL_TEST)
  48. if(NOT DEFINED "${CURL_TEST}")
  49. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  50. "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
  51. if(CMAKE_REQUIRED_LIBRARIES)
  52. set(CURL_TEST_ADD_LIBRARIES
  53. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  54. endif()
  55. message(STATUS "Performing Curl Test ${CURL_TEST}")
  56. try_compile(${CURL_TEST}
  57. ${CMAKE_BINARY_DIR}
  58. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
  59. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  60. "${CURL_TEST_ADD_LIBRARIES}"
  61. OUTPUT_VARIABLE OUTPUT)
  62. if(${CURL_TEST})
  63. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  64. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  65. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  66. "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
  67. "${OUTPUT}\n")
  68. else()
  69. message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
  70. set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
  71. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  72. "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
  73. "${OUTPUT}\n")
  74. endif()
  75. endif()
  76. endmacro()
  77. macro(curl_nroff_check)
  78. find_program(NROFF NAMES gnroff nroff)
  79. if(NROFF)
  80. # Need a way to write to stdin, this will do
  81. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
  82. # Tests for a valid nroff option to generate a manpage
  83. foreach(_MANOPT "-man" "-mandoc")
  84. execute_process(COMMAND "${NROFF}" ${_MANOPT}
  85. OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
  86. INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
  87. ERROR_QUIET)
  88. # Save the option if it was valid
  89. if(NROFF_MANOPT_OUTPUT)
  90. message("Found *nroff option: -- ${_MANOPT}")
  91. set(NROFF_MANOPT ${_MANOPT})
  92. set(NROFF_USEFUL ON)
  93. break()
  94. endif()
  95. endforeach()
  96. # No need for the temporary file
  97. file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
  98. if(NOT NROFF_USEFUL)
  99. message(WARNING "Found no *nroff option to get plaintext from man pages")
  100. endif()
  101. else()
  102. message(WARNING "Found no *nroff program")
  103. endif()
  104. endmacro()