From 7721aab48b16089b3190cde67f2539c00a14918f Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 29 Aug 2021 03:06:14 +0200
Subject: [PATCH] fix Windows static build

---
 CMakeLists.txt            | 7 ++++++-
 src/libragephoto_global.h | 4 ++++
 src/ragephoto.pc.in       | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c40907..87232dd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,15 +34,17 @@ set(RAGEPHOTO_HEADERS
 set(RAGEPHOTO_SOURCES
     src/RagePhoto.cpp
 )
-configure_file(src/ragephoto.pc.in pkgconfig/ragephoto.pc @ONLY)
 
 option(BUILD_SHARED "Build libragephoto as shared library" ON)
 if (BUILD_SHARED)
     add_library(ragephoto SHARED ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES})
     set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
+    set(LIBRAGEPHOTO_LIBTYPE -DLIBRAGEPHOTO_SHARED)
 else()
     add_library(ragephoto STATIC ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES})
+    set(LIBRAGEPHOTO_LIBTYPE -DLIBRAGEPHOTO_STATIC)
 endif()
+configure_file(src/ragephoto.pc.in pkgconfig/ragephoto.pc @ONLY)
 
 option(WITH_BENCHMARK "Build with libragephoto benchmark" OFF)
 if (WITH_BENCHMARK)
@@ -55,6 +57,9 @@ target_compile_definitions(ragephoto PRIVATE
     LIBRAGEPHOTO_LIBRARY
     ${LIBRAGEPHOTO_DEFINES}
 )
+target_compile_definitions(ragephoto PUBLIC
+    ${LIBRAGEPHOTO_LIBTYPE}
+)
 install(TARGETS ragephoto DESTINATION lib)
 install(FILES ${RAGEPHOTO_HEADERS} DESTINATION include)
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/ragephoto.pc DESTINATION lib/pkgconfig)
diff --git a/src/libragephoto_global.h b/src/libragephoto_global.h
index b8f63b2..dcbdda6 100644
--- a/src/libragephoto_global.h
+++ b/src/libragephoto_global.h
@@ -20,6 +20,7 @@
 #define LIBRAGEPHOTO_GLOBAL_H
 
 #ifdef _WIN32
+#ifndef LIBRAGEPHOTO_STATIC
 #ifdef LIBRAGEPHOTO_LIBRARY
 #define LIBRAGEPHOTO_EXPORT __declspec(dllexport)
 #else
@@ -28,5 +29,8 @@
 #else
 #define LIBRAGEPHOTO_EXPORT __attribute__((visibility("default")))
 #endif
+#else
+#define LIBRAGEPHOTO_EXPORT __attribute__((visibility("default")))
+#endif
 
 #endif // LIBRAGEPHOTO_GLOBAL_H
diff --git a/src/ragephoto.pc.in b/src/ragephoto.pc.in
index 965fe75..7414504 100644
--- a/src/ragephoto.pc.in
+++ b/src/ragephoto.pc.in
@@ -6,4 +6,4 @@ Name: libragephoto
 Description: Open Source RAGE Photo Parser for GTA V
 Version: @PROJECT_VERSION@
 Libs: -L${libdir} -lragephoto
-Cflags: -I${includedir}
+Cflags: -I${includedir} @LIBRAGEPHOTO_LIBTYPE@