Macros.cmake 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 appends library to the list.
  4. macro(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE)
  5. check_library_exists("${CURL_LIBS};${LIBRARY}" ${SYMBOL} "${CMAKE_LIBRARY_PATH}"
  6. ${VARIABLE})
  7. if(${VARIABLE})
  8. list(APPEND CURL_LIBS ${LIBRARY})
  9. endif(${VARIABLE})
  10. endmacro(CHECK_LIBRARY_EXISTS_CONCAT)
  11. # Check if header file exists and add it to the list.
  12. macro(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
  13. check_include_file("${FILE}" ${VARIABLE})
  14. if(${VARIABLE})
  15. set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
  16. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
  17. endif(${VARIABLE})
  18. endmacro(CHECK_INCLUDE_FILE_CONCAT)
  19. # For other curl specific tests, use this macro.
  20. macro(CURL_INTERNAL_TEST CURL_TEST)
  21. if("${CURL_TEST}" MATCHES "^${CURL_TEST}$")
  22. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  23. "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
  24. if(CMAKE_REQUIRED_LIBRARIES)
  25. set(CURL_TEST_ADD_LIBRARIES
  26. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  27. endif(CMAKE_REQUIRED_LIBRARIES)
  28. message(STATUS "Performing Curl Test ${CURL_TEST}")
  29. try_compile(${CURL_TEST}
  30. ${CMAKE_BINARY_DIR}
  31. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
  32. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  33. "${CURL_TEST_ADD_LIBRARIES}"
  34. OUTPUT_VARIABLE OUTPUT)
  35. if(${CURL_TEST})
  36. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  37. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  38. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  39. "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
  40. "${OUTPUT}\n")
  41. else(${CURL_TEST})
  42. message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
  43. set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
  44. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  45. "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
  46. "${OUTPUT}\n")
  47. endif(${CURL_TEST})
  48. endif("${CURL_TEST}" MATCHES "^${CURL_TEST}$")
  49. endmacro(CURL_INTERNAL_TEST)
  50. macro(CURL_INTERNAL_TEST_RUN CURL_TEST)
  51. if("${CURL_TEST}_COMPILE" MATCHES "^${CURL_TEST}_COMPILE$")
  52. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  53. "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}")
  54. if(CMAKE_REQUIRED_LIBRARIES)
  55. set(CURL_TEST_ADD_LIBRARIES
  56. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  57. endif(CMAKE_REQUIRED_LIBRARIES)
  58. message(STATUS "Performing Curl Test ${CURL_TEST}")
  59. try_run(${CURL_TEST} ${CURL_TEST}_COMPILE
  60. ${CMAKE_BINARY_DIR}
  61. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
  62. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  63. "${CURL_TEST_ADD_LIBRARIES}"
  64. OUTPUT_VARIABLE OUTPUT)
  65. if(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  66. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  67. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  68. else(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  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}")
  74. if(${CURL_TEST}_COMPILE)
  75. file(APPEND
  76. "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  77. "There was a problem running this test\n")
  78. endif(${CURL_TEST}_COMPILE)
  79. file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  80. "\n\n")
  81. endif(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  82. endif("${CURL_TEST}_COMPILE" MATCHES "^${CURL_TEST}_COMPILE$")
  83. endmacro(CURL_INTERNAL_TEST_RUN)