Macros.cmake 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #File defines convenience macros for available feature testing
  2. # This macro checks if the symbol exists in the library and if it
  3. # does, it prepends library to the list. It is intended to be called
  4. # multiple times with a sequence of possibly dependent libraries in
  5. # order of least-to-most-dependent. Some libraries depend on others
  6. # to link correctly.
  7. macro(check_library_exists_concat LIBRARY SYMBOL VARIABLE)
  8. check_library_exists("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "${CMAKE_LIBRARY_PATH}"
  9. ${VARIABLE})
  10. if(${VARIABLE})
  11. set(CURL_LIBS ${LIBRARY} ${CURL_LIBS})
  12. endif()
  13. endmacro()
  14. # Check if header file exists and add it to the list.
  15. # This macro is intended to be called multiple times with a sequence of
  16. # possibly dependent header files. Some headers depend on others to be
  17. # compiled correctly.
  18. macro(check_include_file_concat FILE VARIABLE)
  19. check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
  20. if(${VARIABLE})
  21. set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
  22. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
  23. endif()
  24. endmacro()
  25. # For other curl specific tests, use this macro.
  26. macro(curl_internal_test CURL_TEST)
  27. if(NOT DEFINED "${CURL_TEST}")
  28. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  29. "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
  30. if(CMAKE_REQUIRED_LIBRARIES)
  31. set(CURL_TEST_ADD_LIBRARIES
  32. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  33. endif()
  34. message(STATUS "Performing Curl Test ${CURL_TEST}")
  35. try_compile(${CURL_TEST}
  36. ${CMAKE_BINARY_DIR}
  37. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
  38. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  39. "${CURL_TEST_ADD_LIBRARIES}"
  40. OUTPUT_VARIABLE OUTPUT)
  41. if(${CURL_TEST})
  42. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  43. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  44. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  45. "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
  46. "${OUTPUT}\n")
  47. else()
  48. message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
  49. set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
  50. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  51. "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
  52. "${OUTPUT}\n")
  53. endif()
  54. endif()
  55. endmacro()
  56. macro(curl_nroff_check)
  57. find_program(NROFF NAMES gnroff nroff)
  58. if(NROFF)
  59. # Need a way to write to stdin, this will do
  60. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
  61. # Tests for a valid nroff option to generate a manpage
  62. foreach(_MANOPT "-man" "-mandoc")
  63. execute_process(COMMAND "${NROFF}" ${_MANOPT}
  64. OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
  65. INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
  66. ERROR_QUIET)
  67. # Save the option if it was valid
  68. if(NROFF_MANOPT_OUTPUT)
  69. message("Found *nroff option: -- ${_MANOPT}")
  70. set(NROFF_MANOPT ${_MANOPT})
  71. set(NROFF_USEFUL ON)
  72. break()
  73. endif()
  74. endforeach()
  75. # No need for the temporary file
  76. file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
  77. if(NOT NROFF_USEFUL)
  78. message(WARNING "Found no *nroff option to get plaintext from man pages")
  79. endif()
  80. else()
  81. message(WARNING "Found no *nroff program")
  82. endif()
  83. endmacro()