From 5a2b8078908dfe4e3b27a988577c2dd151eb6470 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 20 Feb 2023 00:16:55 +0300 Subject: [PATCH] Move import/export macros into CMake --- include/IrrCompileConfig.h | 34 +++++----------------------------- source/Irrlicht/CMakeLists.txt | 15 ++++++++++----- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index 7d3c458..5a4f898 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -25,39 +25,15 @@ #define _IRR_MATERIAL_MAX_TEXTURES_ 4 -#ifdef _IRR_WINDOWS_API_ - -// To build Irrlicht as a static library, you must define _IRR_STATIC_LIB_ in both the -// Irrlicht build, *and* in the user application, before #including -#ifndef _IRR_STATIC_LIB_ -#ifdef IRRLICHT_EXPORTS -#define IRRLICHT_API __declspec(dllexport) -#else -#define IRRLICHT_API __declspec(dllimport) -#endif // IRRLICHT_EXPORT -#else -#define IRRLICHT_API -#endif // _IRR_STATIC_LIB_ - -// Declare the calling convention. -#if defined(_STDCALL_SUPPORTED) +#ifdef _WIN32 #define IRRCALLCONV __stdcall #else -#define IRRCALLCONV __cdecl -#endif // STDCALL_SUPPORTED - -#else // _IRR_WINDOWS_API_ - -// Force symbol export in shared libraries built with gcc. -#if defined(__GNUC__) && !defined(_IRR_STATIC_LIB_) && defined(IRRLICHT_EXPORTS) -#define IRRLICHT_API __attribute__ ((visibility("default"))) -#else -#define IRRLICHT_API +#define IRRCALLCONV #endif -#define IRRCALLCONV - -#endif // _IRR_WINDOWS_API_ +#ifndef IRRLICHT_API +#define IRRLICHT_API +#endif #define _IRR_COMPILE_WITH_GUI_ diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 76228d1..eeb1029 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -4,7 +4,13 @@ option(USE_SDL2 "Use the SDL2 backend" FALSE) # Compiler flags add_definitions(-DIRRLICHT_EXPORTS) -if(NOT BUILD_SHARED_LIBS) +if(BUILD_SHARED_LIBS) + if(WIN32) + add_definitions("-DIRRLICHT_API=__declspec(dllexport)") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") + add_definitions("-DIRRLICHT_API=__attribute__ ((visibility(\"default\")))") + endif() +else() add_definitions(-D_IRR_STATIC_LIB_) endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -453,13 +459,12 @@ target_include_directories(IrrlichtMt target_link_libraries(IrrlichtMt PRIVATE ${link_libs}) -# Propagate static library flag to lib users, only needed for Windows -if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(IrrlichtMt INTERFACE _IRR_STATIC_LIB_) -endif() if(WIN32) target_compile_definitions(IrrlichtMt INTERFACE _IRR_WINDOWS_API_) endif() +if(WIN32 AND BUILD_SHARED_LIBS) + target_compile_definitions(IrrlichtMt INTERFACE IRRLICHT_API=__declspec(dllimport)) +endif() if(APPLE OR ANDROID OR EMSCRIPTEN) target_compile_definitions(IrrlichtMt PUBLIC IRR_MOBILE_PATHS) endif()