Reworked how _UI_EXTERN works to allow MinGW static linking on Windows.

This commit is contained in:
Pietro Gagliardi 2016-06-03 22:19:33 -04:00
parent abcf1edf43
commit 7dcfb8c6c3
2 changed files with 14 additions and 15 deletions

View File

@ -2,11 +2,8 @@
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 2.8.11)
# TODOs: # TODOs:
# - MSVC static linking does not include the .res file in out\, so executables lack the necessary resources # - Windows: static linking does not include the .res file in out\, so executables lack the necessary resources
# - same thing with MinGW? # - Darwin, Unix: static linking temporary target makes PUBLIC properties not propagate
# - MinGW doesn't work in general; windres doesn't like _UI_EXTERN (we could mitigate this by moving the stuff into ui.h and taking advantage of the libui_EXPORTS macro cmake makes for us) but
# - Unix, Darwin: static linking makes the above a moot point; PUBLIC properties don't propagate
# - what is it, the static linking or the extra build step?
# the docs say we need to set this up prior to project() # the docs say we need to set this up prior to project()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.8") set(CMAKE_OSX_DEPLOYMENT_TARGET "10.8")
@ -106,6 +103,9 @@ target_include_directories(${_LIBUINAME}
PRIVATE ${_LIBUI_INCLUEDIRS}) PRIVATE ${_LIBUI_INCLUEDIRS})
target_compile_definitions(${_LIBUINAME} target_compile_definitions(${_LIBUINAME}
PRIVATE ${_LIBUI_DEFS}) PRIVATE ${_LIBUI_DEFS})
# cmake produces this for us by default but only for shared libraries
target_compile_definitions(${_LIBUINAME}
PRIVATE libui_EXPORTS)
target_compile_options(${_LIBUINAME} target_compile_options(${_LIBUINAME}
PUBLIC ${_COMMON_CFLAGS} PUBLIC ${_COMMON_CFLAGS}
PRIVATE ${_LIBUI_CFLAGS}) PRIVATE ${_LIBUI_CFLAGS})
@ -126,14 +126,6 @@ if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(${_LIBUINAME} target_compile_definitions(${_LIBUINAME}
PRIVATE _UI_STATIC) PRIVATE _UI_STATIC)
endif() endif()
# don't put this in the OS CMakeLists.txt to be safe about quoting
if(WIN32)
target_compile_definitions(${_LIBUINAME}
PRIVATE "_UI_EXTERN=__declspec(dllexport) extern")
else()
target_compile_definitions(${_LIBUINAME}
PRIVATE "_UI_EXTERN=__attribute__((visibility(\"default\"))) extern")
endif()
if(NOT WIN32) if(NOT WIN32)
# on non-Windows platforms cmake adds an extra lib- # on non-Windows platforms cmake adds an extra lib-
# note that we apply this to libui, not to any intermediates # note that we apply this to libui, not to any intermediates

11
ui.h
View File

@ -12,8 +12,15 @@
extern "C" { extern "C" {
#endif #endif
// TODO add __declspec(dllimport) on windows // this macro is generated by cmake
#ifndef _UI_EXTERN #ifdef libui_EXPORTS
#ifdef _WIN32
#define _UI_EXTERN __declspec(dllexport) extern
#else
#define _UI_EXTERN __attribute__((visibility("default"))) extern
#endif
#else
// TODO add __declspec(dllimport) on windows, but only if not static
#define _UI_EXTERN extern #define _UI_EXTERN extern
#endif #endif