From 7d2f364256be87e2398d3aa57bbc21cb76eb1451 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 4 Jun 2016 13:57:10 -0400 Subject: [PATCH] Fixed Windows static linking issues. --- CMakeLists.txt | 6 +++--- windows/CMakeLists.txt | 16 +++++++++++++++- windows/resources.rc | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c07c743..f811a658 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 2.8.11) # TODOs: -# - 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() @@ -123,8 +122,9 @@ if(BUILD_SHARED_LIBS) endif() if(NOT BUILD_SHARED_LIBS) _handle_static() + # TODO this really should be PRIVATE but I haven't fully figured this out target_compile_definitions(${_LIBUINAME} - PRIVATE _UI_STATIC) + PUBLIC _UI_STATIC) endif() if(NOT WIN32) # on non-Windows platforms cmake adds an extra lib- @@ -143,7 +143,7 @@ macro(_add_exec _name) add_executable(${_name} WIN32 EXCLUDE_FROM_ALL ${ARGN}) - target_link_libraries(${_name} libui) + target_link_libraries(${_name} libui ${_LIBUI_STATIC_RES}) _target_link_options_private(${_name} _COMMON_LDFLAGS) # make shared-linked executables PIC too diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 84d1f2aa..7119b0a3 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -60,9 +60,23 @@ list(APPEND _LIBUI_INCLUDEDIRS ) set(_LIBUI_INCLUDEDIRS _LIBUI_INCLUDEDIRS PARENT_SCOPE) -# no special handling of static libraries needed set(_LIBUINAME libui PARENT_SCOPE) +if(NOT BUILD_SHARED_LIBS) + set(_LIBUI_STATIC_RES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libui.res PARENT_SCOPE) +endif() macro(_handle_static) + if(MSVC) + set(_res_suffix res) + else() + set(_res_suffix obj) + endif() + # TODO this full path feels hacky + add_custom_command( + TARGET libui PRE_LINK + COMMAND + ${CMAKE_COMMAND} -E copy $/CMakeFiles/libui.dir/windows/resources.rc.${_res_suffix} ${_LIBUI_STATIC_RES} + COMMENT "Copying libui.res") + set(_res_suffix) endmacro() # notice that usp10 comes before gdi32 diff --git a/windows/resources.rc b/windows/resources.rc index 74402dfb..989dfc91 100644 --- a/windows/resources.rc +++ b/windows/resources.rc @@ -6,6 +6,7 @@ #pragma code_page(65001) // this is the Common Controls 6 manifest +// we only define it in a shared build; static builds have to include the appropriate parts of the manifest in the output executable // LONGTERM set up the string values here #ifndef _UI_STATIC ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST "libui.manifest"