1 #File defines convenience macros for available feature testing
3 # This macro checks if the symbol exists in the library and if it
4 # does, it prepends library to the list. It is intended to be called
5 # multiple times with a sequence of possibly dependent libraries in
6 # order of least-to-most-dependent. Some libraries depend on others
8 macro(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE)
9 check_library_exists("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "${CMAKE_LIBRARY_PATH}"
12 set(CURL_LIBS ${LIBRARY} ${CURL_LIBS})
14 endmacro(CHECK_LIBRARY_EXISTS_CONCAT)
16 # Check if header file exists and add it to the list.
17 # This macro is intended to be called multiple times with a sequence of
18 # possibly dependent header files. Some headers depend on others to be
20 macro(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
21 check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
23 set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
24 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
26 endmacro(CHECK_INCLUDE_FILE_CONCAT)
28 # For other curl specific tests, use this macro.
29 macro(CURL_INTERNAL_TEST CURL_TEST)
30 if(NOT DEFINED "${CURL_TEST}")
31 set(MACRO_CHECK_FUNCTION_DEFINITIONS
32 "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
33 if(CMAKE_REQUIRED_LIBRARIES)
34 set(CURL_TEST_ADD_LIBRARIES
35 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
36 endif(CMAKE_REQUIRED_LIBRARIES)
38 message(STATUS "Performing Curl Test ${CURL_TEST}")
39 try_compile(${CURL_TEST}
41 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
42 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
43 "${CURL_TEST_ADD_LIBRARIES}"
44 OUTPUT_VARIABLE OUTPUT)
46 set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
47 message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
48 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
49 "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
52 message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
53 set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
54 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
55 "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
59 endmacro(CURL_INTERNAL_TEST)
61 macro(CURL_INTERNAL_TEST_RUN CURL_TEST)
62 if(NOT DEFINED "${CURL_TEST}_COMPILE")
63 set(MACRO_CHECK_FUNCTION_DEFINITIONS
64 "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}")
65 if(CMAKE_REQUIRED_LIBRARIES)
66 set(CURL_TEST_ADD_LIBRARIES
67 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
68 endif(CMAKE_REQUIRED_LIBRARIES)
70 message(STATUS "Performing Curl Test ${CURL_TEST}")
71 try_run(${CURL_TEST} ${CURL_TEST}_COMPILE
73 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
74 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
75 "${CURL_TEST_ADD_LIBRARIES}"
76 OUTPUT_VARIABLE OUTPUT)
77 if(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
78 set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
79 message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
80 else(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
81 message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
82 set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
83 file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
84 "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
86 if(${CURL_TEST}_COMPILE)
88 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
89 "There was a problem running this test\n")
90 endif(${CURL_TEST}_COMPILE)
91 file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
93 endif(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
95 endmacro(CURL_INTERNAL_TEST_RUN)
97 macro(CURL_NROFF_CHECK)
98 find_program(NROFF NAMES gnroff nroff)
100 # Need a way to write to stdin, this will do
101 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
102 # Tests for a valid nroff option to generate a manpage
103 foreach(_MANOPT "-man" "-mandoc")
104 execute_process(COMMAND "${NROFF}" ${_MANOPT}
105 OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
106 INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
108 # Save the option if it was valid
109 if(NROFF_MANOPT_OUTPUT)
110 message("Found *nroff option: -- ${_MANOPT}")
111 set(NROFF_MANOPT ${_MANOPT})
116 # No need for the temporary file
117 file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
119 message(WARNING "Found no *nroff option to get plaintext from man pages")
122 message(WARNING "Found no *nroff program")
124 endmacro(CURL_NROFF_CHECK)