From 0169a02d200f79268322e6e17b80b2c8e05ea92b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= <simonisfrederic@gmail.com>
Date: Thu, 12 Aug 2021 09:15:47 +0200
Subject: [PATCH 1/5] Simplify CMake flag handling

---
 CMakeLists.txt                     | 17 ++++++++---------
 scribus/CMakeLists.txt             | 11 -----------
 scribus/pluginapi.h                |  9 ++-------
 scribus/scribusapi.h               | 21 +++++++--------------
 scribus/styles/stylecontextproxy.h |  2 +-
 5 files changed, 18 insertions(+), 42 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 491424d98..4a060f328 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -340,7 +340,9 @@ if(NOT WANT_DEBUG AND NOT WANT_RELEASEWITHDEBUG)
 	set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Set Release Build Type" FORCE)
 endif()
 
-
+set(CMAKE_ENABLE_EXPORTS ON)
+set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
 
 #Based on our build type, setup our build options
 if(APPLE)
@@ -354,19 +356,15 @@ else()
 		set(CMAKE_C_FLAGS_DEBUG)
 	else()
 		# vanilla gcc
-		set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -Wall -fstrict-aliasing -Wl,-E")
-		set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g -Wall -fstrict-aliasing -Wl,-E")
-		if (_machine_x86 OR _machine_x86_64)
-			set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC")
-			set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fPIC")
-		endif()
+		set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -Wall -fstrict-aliasing")
+		set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g -Wall -fstrict-aliasing")
 	endif()
 	if(${CMAKE_GENERATOR} MATCHES "^(Visual Studio|NMake).*")
 		set(CMAKE_CXX_FLAGS_RELEASE)
 		set(CMAKE_C_FLAGS_RELEASE)
 	else()
-		set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -Wall -fPIC -Wl,-E")
-		set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -Wall -fPIC -Wl,-E")
+		set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -Wall")
+		set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -Wall")
 	#	add_definitions(-DNDEBUG)
 	endif()
 endif()
@@ -398,6 +396,7 @@ elseif(WANT_CPP17)
 		set(CMAKE_CXX_STANDARD 17)
 endif()
 set (CMAKE_CXX_STANDARD_REQUIRED ON)
+set (CMAKE_CXX_EXTENSIONS OFF)
 
 ##############################################################################################################
 ########## Find Dependencies                                                                        ##########
diff --git a/scribus/CMakeLists.txt b/scribus/CMakeLists.txt
index 1af4aa1c5..cbfc19b7a 100644
--- a/scribus/CMakeLists.txt
+++ b/scribus/CMakeLists.txt
@@ -754,17 +754,6 @@ else()
 	set(WIN32_ONLY_LIBS)
 endif()
 
-##TEST FIX FOR 6897
-# Use the -E / --export-dynamic flag to ensure that symbols in the Scribus
-# binary are in the public symbol table for plugins. The symbols must also
-# be set as SCRIBUS_API if we're building with -fvisibility=hidden .
-# Should fix bug 6897 .
-if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
-	set_target_properties(${EXE_NAME} PROPERTIES LINK_FLAGS -Wl,-E)
-endif ()
-if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND NOT WIN32)
-	set_target_properties(${EXE_NAME} PROPERTIES LINK_FLAGS -Wl,-E)
-endif ()
 ##
 
 
diff --git a/scribus/pluginapi.h b/scribus/pluginapi.h
index 16c208e6e..28808eeaf 100644
--- a/scribus/pluginapi.h
+++ b/scribus/pluginapi.h
@@ -25,13 +25,8 @@ for which a new license (GPL+exception) is in place.
         #endif
     #endif
 #else
-    #ifdef HAVE_GCC_SYMBOL_VISIBILITY
-        #define PLUGIN_API __attribute__ ((visibility("default")))
-        #define PLUGIN_LOCAL __attribute__ ((visibility("hidden")))
-    #else
-        #define PLUGIN_API
-        #define PLUGIN_LOCAL
-    #endif
+    #define PLUGIN_API __attribute__ ((visibility("default")))
+    #define PLUGIN_LOCAL __attribute__ ((visibility("hidden")))
 #endif
 
 #endif
diff --git a/scribus/scribusapi.h b/scribus/scribusapi.h
index c7c5b405d..ccb3f5c1e 100644
--- a/scribus/scribusapi.h
+++ b/scribus/scribusapi.h
@@ -52,26 +52,19 @@ for which a new license (GPL+exception) is in place.
         #endif
     #endif
 #else
-    #ifdef HAVE_GCC_SYMBOL_VISIBILITY
-        /* Forces inclusion of a symbol in the symbol table, so
-           software outside the current library / app can use it. */
-        #define SCRIBUS_API __attribute__ ((visibility("default")))
-        /* Within a section exported with SCRIBUS_API, forces a symbol to be
-           private to the library / app. Good for private members. */
-        #define SCRIBUS_LOCAL __attribute__ ((visibility("hidden")))
-    #else
-        #define SCRIBUS_API
-        #define SCRIBUS_LOCAL
-    #endif
+    /* Forces inclusion of a symbol in the symbol table, so
+       software outside the current library / app can use it. */
+    #define SCRIBUS_API __attribute__ ((visibility("default")))
+    /* Within a section exported with SCRIBUS_API, forces a symbol to be
+       private to the library / app. Good for private members. */
+    #define SCRIBUS_LOCAL __attribute__ ((visibility("hidden")))
 #endif
 
 /* Throwable classes must always be visible on GCC in all binaries */
 #ifdef WIN32
   #define SCEXCEPTIONAPI(api) api
-#elif defined(HAVE_GCC_SYMBOL_VISIBILITY)
-  #define SCEXCEPTIONAPI(api) SCRIBUS_API
 #else
-  #define SCEXCEPTIONAPI(api)
+  #define SCEXCEPTIONAPI(api) SCRIBUS_API
 #endif
 
 #endif
diff --git a/scribus/styles/stylecontextproxy.h b/scribus/styles/stylecontextproxy.h
index e2b7cbea3..aa656564c 100644
--- a/scribus/styles/stylecontextproxy.h
+++ b/scribus/styles/stylecontextproxy.h
@@ -30,7 +30,7 @@
 *  it maps the empty name "" to the given default style and uses
 *  the style's context to resolve all other names.
 */
-class StyleContextProxy: public StyleContext 
+class SCRIBUS_API StyleContextProxy: public StyleContext 
 {
 public:
 	const BaseStyle* resolve(const QString& name) const;
-- 
2.32.0

