Determine the function export attribute using CMake

This commit is contained in:
Chris Robinson
2011-05-17 09:13:55 -07:00
parent b5cb2d633c
commit 60965e3a6c
4 changed files with 38 additions and 49 deletions
+27 -25
View File
@@ -60,6 +60,8 @@ SET(LIB_MAJOR_VERSION "1")
SET(LIB_MINOR_VERSION "13")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}")
SET(EXPORT_DECL "")
CHECK_TYPE_SIZE("long" SIZEOF_LONG)
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
@@ -144,34 +146,34 @@ ELSE()
CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
ENDIF()
# Set visibility options if available
IF(NOT WIN32)
CHECK_C_COMPILER_FLAG(-fvisibility=internal HAVE_VISIBILITY_SWITCH)
IF(HAVE_VISIBILITY_SWITCH)
CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
int main() {return 0;}" HAVE_GCC_VISIBILITY)
IF(HAVE_GCC_VISIBILITY)
ADD_DEFINITIONS(-fvisibility=internal -DHAVE_GCC_VISIBILITY)
ENDIF()
ENDIF()
ELSE()
OPTION(WINE "Enable use of Wine headers when compiling" ON)
IF(WINE)
FIND_PATH(WINE_INCLUDE_DIR library.h
PATHS
/usr/include/wine
/usr/local/include/wine
PATH_SUFFIXES ".")
IF(WINE_INCLUDE_DIR)
MESSAGE(STATUS "Found Wine header files - ${WINE_INCLUDE_DIR}" )
INCLUDE_DIRECTORIES("${WINE_INCLUDE_DIR}/windows")
SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${WINE_INCLUDE_DIR}/windows")
ELSE()
MESSAGE(STATUS "Could not find Wine header files" )
ENDIF()
# Set visibility/export options if available
IF(WIN32)
SET(EXPORT_DECL "__declspec(dllexport)")
OPTION(WINE "Enable use of Wine headers when compiling" ON)
IF(WINE)
FIND_PATH(WINE_INCLUDE_DIR library.h
PATHS
/usr/include/wine
/usr/local/include/wine)
IF(WINE_INCLUDE_DIR)
MESSAGE(STATUS "Found Wine header files - ${WINE_INCLUDE_DIR}" )
INCLUDE_DIRECTORIES("${WINE_INCLUDE_DIR}/windows")
SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${WINE_INCLUDE_DIR}/windows")
ELSE()
MESSAGE(STATUS "Could not find Wine header files" )
ENDIF()
ENDIF()
ELSE()
CHECK_C_COMPILER_FLAG(-fvisibility=internal HAVE_VISIBILITY_SWITCH)
CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
int main() {return 0;}" HAVE_GCC_VISIBILITY)
IF(HAVE_VISIBILITY_SWITCH AND HAVE_GCC_VISIBILITY)
ADD_DEFINITIONS(-fvisibility=internal)
SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
ENDIF()
ENDIF()
CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
+3 -4
View File
@@ -1,5 +1,6 @@
#ifndef CONFIG_H
#define CONFIG_H
/* API declaration export attribute */
#define AL_API ${EXPORT_DECL}
#define ALC_API ${EXPORT_DECL}
/* Define to the library version */
#define ALSOFT_VERSION "${LIB_VERSION}"
@@ -105,5 +106,3 @@
/* Define if we have the __restrict keyword */
#cmakedefine HAVE___RESTRICT
#endif
+4 -10
View File
@@ -5,17 +5,11 @@
extern "C" {
#endif
#if defined(AL_LIBTYPE_STATIC)
#define AL_API
#elif defined(_WIN32) && !defined(_XBOX)
#if defined(AL_BUILD_LIBRARY)
#define AL_API __declspec(dllexport)
#else
#ifndef AL_API
#if defined(AL_LIBTYPE_STATIC)
#define AL_API
#elif defined(_WIN32)
#define AL_API __declspec(dllimport)
#endif
#else
#if defined(AL_BUILD_LIBRARY) && defined(HAVE_GCC_VISIBILITY)
#define AL_API __attribute__((visibility("protected")))
#else
#define AL_API extern
#endif
+4 -10
View File
@@ -5,17 +5,11 @@
extern "C" {
#endif
#if defined(AL_LIBTYPE_STATIC)
#define ALC_API
#elif defined(_WIN32) && !defined(_XBOX)
#if defined(AL_BUILD_LIBRARY)
#define ALC_API __declspec(dllexport)
#else
#ifndef ALC_API
#if defined(AL_LIBTYPE_STATIC)
#define ALC_API
#elif defined(_WIN32)
#define ALC_API __declspec(dllimport)
#endif
#else
#if defined(AL_BUILD_LIBRARY) && defined(HAVE_GCC_VISIBILITY)
#define ALC_API __attribute__((visibility("protected")))
#else
#define ALC_API extern
#endif