aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-02-16 05:36:49 -0800
committerChris Robinson <[email protected]>2010-02-16 05:36:49 -0800
commit2083884ae329072b316e725330af92f683786451 (patch)
tree9e4ababb91633c6ab5e5a6b17d634cfff79be073
parent2f644c7ed5d72ec1a469be3e028923d475403f0b (diff)
Properly check for functions in Win32 shared libs
-rw-r--r--CMakeLists.txt14
-rw-r--r--cmake/CheckSharedFunctionExists.c38
-rw-r--r--cmake/CheckSharedLibraryExists.cmake67
3 files changed, 111 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e30f4ff1..97723be9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,6 +10,7 @@ SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
INCLUDE(CheckFunctionExists)
INCLUDE(CheckLibraryExists)
+INCLUDE(CheckSharedLibraryExists)
INCLUDE(CheckIncludeFile)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckSymbolExists)
@@ -309,7 +310,7 @@ SET(BACKENDS "")
IF(ALSA)
CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
IF(HAVE_ALSA_ASOUNDLIB_H)
- CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
+ CHECK_SHARED_LIBRARY_EXISTS(asound snd_pcm_open 4 "" HAVE_LIBASOUND)
IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
SET(HAVE_ALSA 1)
SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
@@ -347,7 +348,7 @@ ENDIF()
IF(DSOUND)
CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
IF(HAVE_DSOUND_H)
- CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
+ CHECK_SHARED_LIBRARY_EXISTS(dsound DirectSoundCreate 3 "" HAVE_LIBDSOUND)
IF(HAVE_LIBDSOUND OR WIN32)
SET(HAVE_DSOUND 1)
SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
@@ -365,10 +366,7 @@ IF(HAVE_WINDOWS_H)
IF(WINMM)
CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
IF(HAVE_MMSYSTEM_H)
- SET(CMAKE_REQUIRED_LIBRARIES winmm)
- CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
- SET(CMAKE_REQUIRED_LIBRARIES "")
-# CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
+ CHECK_SHARED_LIBRARY_EXISTS(winmm waveInOpen 6 "" HAVE_LIBWINMM)
IF(HAVE_LIBWINMM)
SET(HAVE_WINMM 1)
SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
@@ -384,7 +382,7 @@ ENDIF()
IF(PORTAUDIO)
CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
IF(HAVE_PORTAUDIO_H)
- CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
+ CHECK_SHARED_LIBRARY_EXISTS(portaudio Pa_Initialize 0 "" HAVE_LIBPORTAUDIO)
IF(HAVE_LIBPORTAUDIO)
SET(HAVE_PORTAUDIO 1)
SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
@@ -402,7 +400,7 @@ ENDIF()
IF(PULSEAUDIO)
CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
IF(HAVE_PULSE_PULSEAUDIO_H)
- CHECK_LIBRARY_EXISTS(pulse pa_context_new "" HAVE_LIBPULSE)
+ CHECK_SHARED_LIBRARY_EXISTS(pulse pa_context_new 2 "" HAVE_LIBPULSE)
IF(HAVE_LIBPULSE)
SET(HAVE_PULSEAUDIO 1)
SET(ALC_OBJS ${ALC_OBJS} Alc/pulseaudio.c)
diff --git a/cmake/CheckSharedFunctionExists.c b/cmake/CheckSharedFunctionExists.c
new file mode 100644
index 00000000..31e3fa92
--- /dev/null
+++ b/cmake/CheckSharedFunctionExists.c
@@ -0,0 +1,38 @@
+#ifdef CHECK_SHARED_FUNCTION_EXISTS
+
+#include <stdlib.h>
+
+#ifndef CALLSTACK
+#define CALLSTACK
+#endif
+
+#ifdef _WIN32
+#ifdef ARGSTACK
+char __stdcall CHECK_SHARED_FUNCTION_EXISTS(ARGSTACK);
+#else
+char __stdcall CHECK_SHARED_FUNCTION_EXISTS(void);
+#endif
+#else
+char CHECK_SHARED_FUNCTION_EXISTS();
+#endif
+
+#ifdef __CLASSIC_C__
+int main(){
+ int ac;
+ char*av[];
+#else
+int main(int ac, char*av[]){
+#endif
+ CHECK_SHARED_FUNCTION_EXISTS(CALLSTACK);
+ if(ac > 1000)
+ {
+ return *av[0];
+ }
+ return 0;
+}
+
+#else /* CHECK_SHARED_FUNCTION_EXISTS */
+
+# error "CHECK_SHARED_FUNCTION_EXISTS has to specify the function"
+
+#endif /* CHECK_SHARED_FUNCTION_EXISTS */
diff --git a/cmake/CheckSharedLibraryExists.cmake b/cmake/CheckSharedLibraryExists.cmake
new file mode 100644
index 00000000..0dbb5b90
--- /dev/null
+++ b/cmake/CheckSharedLibraryExists.cmake
@@ -0,0 +1,67 @@
+# - Check if the function exists.
+# CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE)
+#
+# LIBRARY - the name of the library you are looking for
+# FUNCTION - the name of the function
+# ARGCOUNT - number of arguments for stdcall functions
+# LOCATION - location where the library should be found
+# VARIABLE - variable to store the result
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+
+MACRO(CHECK_SHARED_LIBRARY_EXISTS LIBRARY FUNCTION ARGCOUNT LOCATION VARIABLE)
+ IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+ SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
+ "-DCHECK_SHARED_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
+ IF(WIN32)
+ IF(${ARGCOUNT} GREATER 0)
+ SET(ARGSTACK "void*")
+ SET(CALLSTACK "NULL")
+ SET(CURARG 1)
+ WHILE(${ARGCOUNT} GREATER ${CURARG})
+ SET(ARGSTACK "${ARGSTACK},void*")
+ SET(CALLSTACK "${CALLSTACK},NULL")
+ MATH(EXPR CURARG "${CURARG} + 1")
+ ENDWHILE(${ARGCOUNT} GREATER ${CURARG})
+ ENDIF(${ARGCOUNT} GREATER 0)
+ SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
+ "-D_WIN32 -DARGSTACK=\"${ARGSTACK}\" -DCALLSTACK=\"${CALLSTACK}\" ${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}")
+ ENDIF(WIN32)
+ MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
+ SET(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
+ IF(CMAKE_REQUIRED_LIBRARIES)
+ SET(CHECK_LIBRARY_EXISTS_LIBRARIES
+ ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
+ ENDIF(CMAKE_REQUIRED_LIBRARIES)
+ TRY_COMPILE(${VARIABLE}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/cmake/CheckSharedFunctionExists.c
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ CMAKE_FLAGS
+ -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
+ -DLINK_DIRECTORIES:STRING=${LOCATION}
+ "-DLINK_LIBRARIES:STRING=${CHECK_LIBRARY_EXISTS_LIBRARIES}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ IF(${VARIABLE})
+ MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
+ SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
+ "passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ ELSE(${VARIABLE})
+ MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
+ SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
+ "failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ ENDIF(${VARIABLE})
+ ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+ENDMACRO(CHECK_SHARED_LIBRARY_EXISTS)