diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d965e60..0c07c743 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,8 @@ cmake_minimum_required(VERSION 2.8.11) # TODOs: -# - MSVC static linking does not include the .res file in out\, so executables lack the necessary resources -# - same thing with MinGW? -# - 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? +# - Windows: static linking does not include the .res file in out\, so executables lack the necessary resources +# - Darwin, Unix: static linking temporary target makes PUBLIC properties not propagate # the docs say we need to set this up prior to project() set(CMAKE_OSX_DEPLOYMENT_TARGET "10.8") @@ -106,6 +103,9 @@ target_include_directories(${_LIBUINAME} PRIVATE ${_LIBUI_INCLUEDIRS}) target_compile_definitions(${_LIBUINAME} 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} PUBLIC ${_COMMON_CFLAGS} PRIVATE ${_LIBUI_CFLAGS}) @@ -126,14 +126,6 @@ if(NOT BUILD_SHARED_LIBS) target_compile_definitions(${_LIBUINAME} PRIVATE _UI_STATIC) 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) # on non-Windows platforms cmake adds an extra lib- # note that we apply this to libui, not to any intermediates diff --git a/ui.h b/ui.h index 34527918..c7a8858b 100644 --- a/ui.h +++ b/ui.h @@ -12,8 +12,15 @@ extern "C" { #endif -// TODO add __declspec(dllimport) on windows -#ifndef _UI_EXTERN +// this macro is generated by cmake +#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 #endif