[mman] Fix static linkage. Fixes #2856.

This commit is contained in:
Robert Schumacher 2018-02-22 05:16:06 -08:00
parent fe41bfecd6
commit 1f9c73454b
3 changed files with 46 additions and 8 deletions

View File

@ -1,3 +1,3 @@
Source: mman
Version: git-f5ff813
Version: git-f5ff813-1
Description: A light implementation of the mmap functions for MinGW.

View File

@ -0,0 +1,33 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4696ad4..a72bbce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,10 @@ option (BUILD_TESTS "tests?" OFF)
set (headers mman.h)
set (sources mman.c)
+if(NOT BUILD_SHARED_LIBS)
+ add_definitions(-DMMANSHARED_EXPORT=)
+endif()
+
add_library (mman ${sources})
install (TARGETS mman RUNTIME DESTINATION bin
diff --git a/mman.h b/mman.h
index 4065bc6..435ea26 100644
--- a/mman.h
+++ b/mman.h
@@ -15,11 +15,13 @@
#include <_mingw.h>
#endif
+#if !defined(MMANSHARED_EXPORT)
#if defined(MMAN_LIBRARY)
#define MMANSHARED_EXPORT __declspec(dllexport)
#else
#define MMANSHARED_EXPORT __declspec(dllimport)
#endif
+#endif
/* Determine offset type */
#include <stdint.h>

View File

@ -8,16 +8,15 @@ vcpkg_from_github(
HEAD_REF master
)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
set(ENABLE_SHARED OFF)
else()
set(ENABLE_SHARED ON)
endif()
vcpkg_apply_patches(
SOURCE_PATH ${SOURCE_PATH}
PATCHES
${CMAKE_CURRENT_LIST_DIR}/mman-static.patch
)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
-DBUILD_SHARED_LIBS=${ENABLE_SHARED}
PREFER_NINJA
)
vcpkg_install_cmake()
@ -25,4 +24,10 @@ vcpkg_install_cmake()
file(INSTALL ${SOURCE_PATH}/README.md DESTINATION ${CURRENT_PACKAGES_DIR}/share/mman RENAME copyright)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(READ ${CURRENT_PACKAGES_DIR}/include/sys/mman.h _contents)
string(REPLACE "__declspec(dllimport)" "" _contents "${_contents}")
file(WRITE ${CURRENT_PACKAGES_DIR}/include/sys/mman.h "${_contents}")
endif()
vcpkg_copy_pdbs()