Macros.cmake 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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)