Fully progress the source to a stopped state when no buffers are playable
[openal-soft.git] / cmake / CheckSharedLibraryExists.cmake
blob0069d892da95d02ff391522a0974a0ce6c1ebe72
1 # - Check if the function exists.
2 # CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE)
4 #  LIBRARY  - the name of the library you are looking for
5 #  FUNCTION - the name of the function
6 #  ARGCOUNT - number of arguments for stdcall functions
7 #  LOCATION - location where the library should be found
8 #  VARIABLE - variable to store the result
10 # The following variables may be set before calling this macro to
11 # modify the way the check is run:
13 #  CMAKE_REQUIRED_FLAGS = string of compile command line flags
14 #  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
15 #  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
17 MACRO(CHECK_SHARED_LIBRARY_EXISTS LIBRARY FUNCTION ARGCOUNT LOCATION VARIABLE)
18   IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
19     SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION 
20       "-DCHECK_SHARED_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
21     IF(WIN32)
22         IF(${ARGCOUNT} GREATER 0)
23             SET(ARGSTACK "void*")
24             SET(CALLSTACK "NULL")
25             SET(CURARG 1)
26             WHILE(${ARGCOUNT} GREATER ${CURARG})
27                 SET(ARGSTACK "${ARGSTACK},void*")
28                 SET(CALLSTACK "${CALLSTACK},NULL")
29                 MATH(EXPR CURARG "${CURARG} + 1")
30             ENDWHILE(${ARGCOUNT} GREATER ${CURARG})
31             SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
32                 "-D_WIN32 -DARGSTACK=\"${ARGSTACK}\" -DCALLSTACK=\"${CALLSTACK}\" ${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}")
33         ELSE(${ARGCOUNT} GREATER 0)
34             SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
35                 "-D_WIN32 ${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}")
36         ENDIF(${ARGCOUNT} GREATER 0)
37     ENDIF(WIN32)
38     MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
39     SET(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
40     IF(CMAKE_REQUIRED_LIBRARIES)
41       SET(CHECK_LIBRARY_EXISTS_LIBRARIES 
42         ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
43     ENDIF(CMAKE_REQUIRED_LIBRARIES)
44     TRY_COMPILE(${VARIABLE}
45       ${CMAKE_BINARY_DIR}
46       ${CMAKE_SOURCE_DIR}/cmake/CheckSharedFunctionExists.c
47       COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
48       CMAKE_FLAGS 
49       -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
50       -DLINK_DIRECTORIES:STRING=${LOCATION}
51       "-DLINK_LIBRARIES:STRING=${CHECK_LIBRARY_EXISTS_LIBRARIES}"
52       OUTPUT_VARIABLE OUTPUT)
54     IF(${VARIABLE})
55       MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
56       SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
57       FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
58         "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
59         "passed with the following output:\n"
60         "${OUTPUT}\n\n")
61     ELSE(${VARIABLE})
62       MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
63       SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
64       FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
65         "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
66         "failed with the following output:\n"
67         "${OUTPUT}\n\n")
68     ENDIF(${VARIABLE})
69   ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
70 ENDMACRO(CHECK_SHARED_LIBRARY_EXISTS)