feature: introduce DRANG_PLATFORM_BUILD_SHARED option for shared library builds

This commit is contained in:
MechSlayer 2025-09-05 17:03:27 +02:00
parent 505539f1cd
commit e857d1a896
4 changed files with 16 additions and 14 deletions

View file

@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.21)
project(DrangPlatform VERSION 1.0.0 LANGUAGES C)
option(DRANG_PLATFORM_BUILD_SHARED "Build DrangPlatform as a shared library" OFF)
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
@ -25,4 +27,5 @@ set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE)
set(MI_USE_CXX OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(mimalloc)
add_subdirectory(Source/DrangPlatform)

View file

@ -50,7 +50,7 @@
"displayName": "x64 Debug Shared",
"inherits": "win64-debug",
"cacheVariables": {
"BUILD_SHARED_LIBS": "ON"
"DRANG_PLATFORM_BUILD_SHARED": "ON"
}
},
{
@ -70,7 +70,7 @@
"displayName": "x64 Release Shared",
"inherits": "win64-release",
"cacheVariables": {
"BUILD_SHARED_LIBS": "ON"
"DRANG_PLATFORM_BUILD_SHARED": "ON"
}
},
{
@ -90,7 +90,7 @@
"displayName": "x64 Debug Shared",
"inherits": "linux64-debug",
"cacheVariables": {
"BUILD_SHARED_LIBS": "ON"
"DRANG_PLATFORM_BUILD_SHARED": "ON"
}
},
{
@ -110,7 +110,7 @@
"displayName": "x64 Release Shared",
"inherits": "linux64-release",
"cacheVariables": {
"BUILD_SHARED_LIBS": "ON"
"DRANG_PLATFORM_BUILD_SHARED": "ON"
}
}
]

View file

@ -52,7 +52,7 @@ collect_platform_sources(MODULE_PRIVATE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Sourc
collect_platform_sources(MODULE_PUBLIC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Include")
set(MODULE_FILES ${MODULE_PRIVATE_FILES} ${MODULE_PUBLIC_FILES})
if (${BUILD_SHARED_LIBS})
if (${DRANG_PLATFORM_BUILD_SHARED})
add_library(${MODULE_NAME} SHARED ${MODULE_FILES})
target_compile_definitions(${MODULE_NAME} PRIVATE DRANG_PLATFORM_EXPORT=1)
else ()

View file

@ -1,21 +1,20 @@
#pragma once
#ifdef _WIN32
#define DRANG_DLL_EXPORT __declspec(dllexport)
#define DRANG_DLL_IMPORT __declspec(dllimport)
# define DRANG_DLL_EXPORT __declspec(dllexport)
# define DRANG_DLL_IMPORT __declspec(dllimport)
#elif defined(__linux__)
#define DRANG_DLL_EXPORT __attribute__((visibility("default")))
#define DRANG_DLL_IMPORT __attribute__((visibility("default")))
# define DRANG_DLL_EXPORT __attribute__((visibility("default")))
# define DRANG_DLL_IMPORT __attribute__((visibility("default")))
#else
#error "Unknown platform, please implement shared library export/import macros"
# error "Unknown platform, please implement shared library export/import macros"
#endif
#if !DRANG_PLATFORM_STATIC
# if DRANG_PLATFORM_EXPORT
#define DRANG_PLATFORM_API DRANG_DLL_EXPORT
#else
#define DRANG_PLATFORM_API DRANG_DLL_IMPORT
# define DRANG_PLATFORM_API DRANG_DLL_EXPORT
# else
# define DRANG_PLATFORM_API DRANG_DLL_IMPORT
# endif
#else
# define DRANG_PLATFORM_API