Macros.cmake 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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(${VARIABLE})
  13. endmacro(CHECK_LIBRARY_EXISTS_CONCAT)
  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(${VARIABLE})
  24. endmacro(CHECK_INCLUDE_FILE_CONCAT)
  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(CMAKE_REQUIRED_LIBRARIES)
  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(${CURL_TEST})
  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(${CURL_TEST})
  54. endif()
  55. endmacro(CURL_INTERNAL_TEST)
  56. macro(CURL_INTERNAL_TEST_RUN CURL_TEST)
  57. if(NOT DEFINED "${CURL_TEST}_COMPILE")
  58. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  59. "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}")
  60. if(CMAKE_REQUIRED_LIBRARIES)
  61. set(CURL_TEST_ADD_LIBRARIES
  62. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  63. endif(CMAKE_REQUIRED_LIBRARIES)
  64. message(STATUS "Performing Curl Test ${CURL_TEST}")
  65. try_run(${CURL_TEST} ${CURL_TEST}_COMPILE
  66. ${CMAKE_BINARY_DIR}
  67. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
  68. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  69. "${CURL_TEST_ADD_LIBRARIES}"
  70. OUTPUT_VARIABLE OUTPUT)
  71. if(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  72. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  73. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  74. else(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  75. message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
  76. set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
  77. file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  78. "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
  79. "${OUTPUT}")
  80. if(${CURL_TEST}_COMPILE)
  81. file(APPEND
  82. "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  83. "There was a problem running this test\n")
  84. endif(${CURL_TEST}_COMPILE)
  85. file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  86. "\n\n")
  87. endif(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  88. endif()
  89. endmacro(CURL_INTERNAL_TEST_RUN)
  90. macro(CURL_NROFF_CHECK)
  91. find_program(NROFF NAMES gnroff nroff)
  92. if(NROFF)
  93. # Need a way to write to stdin, this will do
  94. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
  95. # Tests for a valid nroff option to generate a manpage
  96. foreach(_MANOPT "-man" "-mandoc")
  97. execute_process(COMMAND "${NROFF}" ${_MANOPT}
  98. OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
  99. INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
  100. ERROR_QUIET)
  101. # Save the option if it was valid
  102. if(NROFF_MANOPT_OUTPUT)
  103. message("Found *nroff option: -- ${_MANOPT}")
  104. set(NROFF_MANOPT ${_MANOPT})
  105. set(NROFF_USEFUL ON)
  106. break()
  107. endif()
  108. endforeach()
  109. # No need for the temporary file
  110. file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
  111. if(NOT NROFF_USEFUL)
  112. message(WARNING "Found no *nroff option to get plaintext from man pages")
  113. endif()
  114. else()
  115. message(WARNING "Found no *nroff program")
  116. endif()
  117. endmacro(CURL_NROFF_CHECK)