Skip to content
Permalink
Browse files

Hide shared library symbols by default on GCC and Clang

 * Decreases lib size, loading time and compile time
 * Forces people on linux to use the {LIB}_EXPORT defines and therefore will
   make Windows nightlies more reliable
  • Loading branch information
m-kuhn committed May 23, 2015
1 parent 76aa035 commit c1b520fbd8110851bb78c817e2cfa5ecda103e85
@@ -363,6 +363,7 @@ IF (NOT USE_CXX_11)
ADD_DEFINITIONS("-Doverride=")
ENDIF()


#############################################################
# enable warnings

@@ -578,14 +579,20 @@ IF (WIN32)
SET(DLLIMPORT "__declspec(dllimport)")
SET(DLLEXPORT "__declspec(dllexport)")
ELSE (WIN32)
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(DLLEXPORT "__attribute__ ((visibility (\\\"default\\\")))")
ELSE()
SET(DLLEXPORT "")
ENDIF()

SET(DLLIMPORT "")

IF(PEDANTIC AND NOT APPLE)
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
ENDIF(PEDANTIC AND NOT APPLE)

SET(DLLIMPORT "")
SET(DLLEXPORT "")
ENDIF(WIN32)

ADD_DEFINITIONS("-DCORE_EXPORT=${DLLIMPORT}")
@@ -137,14 +137,13 @@ INCLUDE_DIRECTORIES(
${GDAL_INCLUDE_DIR}
)

IF (WIN32)
IF (MSVC)
ADD_DEFINITIONS("-DANALYSIS_EXPORT=${DLLEXPORT}")
ELSE (MSVC)
ADD_DEFINITIONS("-UANALYSIS_EXPORT \"-DANALYSIS_EXPORT=${DLLEXPORT}\"")
ENDIF (MSVC)
ENDIF (WIN32)

IF (NOT MSVC)
ADD_DEFINITIONS("-UANALYSIS_EXPORT")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
ENDIF()
ENDIF (NOT MSVC)
ADD_DEFINITIONS("\"-DANALYSIS_EXPORT=${DLLEXPORT}\"")

#############################################################
# qgis_analysis library
@@ -495,13 +495,13 @@ ELSE (ANDROID)
ADD_EXECUTABLE(${QGIS_APP_NAME} MACOSX_BUNDLE WIN32 main.cpp ${QGIS_APP_SRCS} ${QGIS_APP_MOC_SRCS} ${IMAGE_RCC_SRCS} ${TEST_RCC_SRCS})
ENDIF (ANDROID)

IF (WIN32)
IF (MSVC)
ADD_DEFINITIONS("-DAPP_EXPORT=${DLLEXPORT}")
ELSE (MSVC)
ADD_DEFINITIONS("-UAPP_EXPORT \"-DAPP_EXPORT=${DLLEXPORT}\"")
ENDIF (MSVC)
ENDIF (WIN32)
IF (NOT MSVC)
ADD_DEFINITIONS("-UAPP_EXPORT")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
ENDIF()
ENDIF (NOT MSVC)
ADD_DEFINITIONS("\"-DAPP_EXPORT=${DLLEXPORT}\"")

# shared library used by tests - TODO: use it also for qgis executable?
ADD_LIBRARY(qgis_app SHARED ${QGIS_APP_SRCS} ${QGIS_APP_MOC_SRCS} ${QGIS_APP_HDRS} ${QGIS_APP_MOC_HDRS} ${IMAGE_RCC_SRCS})
@@ -707,14 +707,14 @@ INCLUDE_DIRECTORIES(
${SPATIALITE_INCLUDE_DIR}
)

IF (NOT MSVC)
ADD_DEFINITIONS("-UCORE_EXPORT")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
ENDIF()
ENDIF (NOT MSVC)
ADD_DEFINITIONS("\"-DCORE_EXPORT=${DLLEXPORT}\"")

IF (WIN32)
IF (MSVC)
ADD_DEFINITIONS("-DCORE_EXPORT=${DLLEXPORT}")
ELSE (MSVC)
ADD_DEFINITIONS("-UCORE_EXPORT \"-DCORE_EXPORT=${DLLEXPORT}\"")
ENDIF (MSVC)
ENDIF (WIN32)

#for PAL classes
IF (WIN32)
@@ -372,7 +372,7 @@ bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );

bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );

QString qgsVsiPrefix( QString path );
CORE_EXPORT QString qgsVsiPrefix( QString path );

/** Allocates size bytes and returns a pointer to the allocated memory.
Works like C malloc() but prints debug message by QgsLogger if allocation fails.
@@ -471,7 +471,11 @@ typedef unsigned long long qgssize;
# pragma warning(disable:4190)
# endif
#else
# define QGISEXTERN extern "C"
# if defined(__GNUC__) || defined(__clang__)
# define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
# else
# define QGISEXTERN extern "C"
# endif
#endif
#endif
#endif
@@ -8,13 +8,14 @@ ENDIF (QT5_BUILD)

SET(QT_USE_QTDESIGNER ON)

IF (WIN32)
IF (MSVC)
ADD_DEFINITIONS("-DCUSTOMWIDGETS_EXPORT=${DLLEXPORT}")
ELSE (MSVC)
ADD_DEFINITIONS("-UCUSTOMWIDGETS_EXPORT \"-DCUSTOMWIDGETS_EXPORT=${DLLEXPORT}\"")
ENDIF (MSVC)
ENDIF (WIN32)

IF (NOT MSVC)
ADD_DEFINITIONS("-UCUSTOMWIDGETS_EXPORT")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
ENDIF()
ENDIF (NOT MSVC)
ADD_DEFINITIONS("\"-DCUSTOMWIDGETS_EXPORT=${DLLEXPORT}\"")

########################################################
# Files
@@ -576,13 +576,13 @@ INCLUDE_DIRECTORIES(${QSCINTILLA_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${GEOS_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${GDAL_INCLUDE_DIR})

IF (WIN32)
IF (MSVC)
ADD_DEFINITIONS("-DGUI_EXPORT=${DLLEXPORT}")
ELSE (MSVC)
ADD_DEFINITIONS("-UGUI_EXPORT \"-DGUI_EXPORT=${DLLEXPORT}\"")
ENDIF (MSVC)
ENDIF (WIN32)
IF (NOT MSVC)
ADD_DEFINITIONS("-UGUI_EXPORT")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
ENDIF()
ENDIF (NOT MSVC)
ADD_DEFINITIONS("\"-DGUI_EXPORT=${DLLEXPORT}\"")

# disable deprecation warnings for classes re-exporting deprecated methods
IF(MSVC)
@@ -44,7 +44,7 @@ class QgsVectorLayerTools;
#include <QPair>
#include <map>

#include <qgis.h>
#include "qgis.h"


/** \ingroup gui
@@ -592,13 +592,4 @@ class GUI_EXPORT QgisInterface : public QObject
void layerSavedAs( QgsMapLayer* l, QString path );
};

// FIXME: also in core/qgis.h
#ifndef QGISEXTERN
#ifdef WIN32
# define QGISEXTERN extern "C" __declspec( dllexport )
#else
# define QGISEXTERN extern "C"
#endif
#endif

#endif //#ifndef QGISINTERFACE_H
@@ -73,12 +73,6 @@
#include <QApplication>
#include <QCursor>

#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
#else
#define QGISEXTERN extern "C"
#endif

static const QString sName = QObject::tr( "eVis" );
static const QString sDescription = QObject::tr( "An event visualization tool - view images associated with vector features" );
static const QString sCategory = QObject::tr( "Database" );
@@ -1,13 +1,10 @@
IF (WIN32)
IF (MSVC)
ADD_DEFINITIONS("-DPYTHON_EXPORT=${DLLEXPORT}")
ELSE (MSVC)
ADD_DEFINITIONS("\"-DPYTHON_EXPORT=${DLLEXPORT}\"")
ENDIF (MSVC)
ELSE (WIN32)
# other compilers don't use that MSVC construct
ADD_DEFINITIONS(-DPYTHON_EXPORT=)
ENDIF (WIN32)
IF (NOT MSVC)
ADD_DEFINITIONS("-UPYTHON_EXPORT")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
ENDIF()
ENDIF (NOT MSVC)
ADD_DEFINITIONS("\"-DPYTHON_EXPORT=${DLLEXPORT}\"")

SET(QGISPYTHON_SRCS qgispython.cpp qgspythonutilsimpl.cpp)

@@ -77,13 +77,13 @@ SET(qgis_mapserv_SRCS ${qgis_mapserv_SRCS}
qgsserverinterfaceimpl.cpp
)

IF (WIN32)
IF (MSVC)
ADD_DEFINITIONS("-DSERVER_EXPORT=${DLLEXPORT}")
ELSE (MSVC)
ADD_DEFINITIONS("-USERVER_EXPORT \"-DSERVER_EXPORT=${DLLEXPORT}\"")
ENDIF (MSVC)
ENDIF (WIN32)
IF (NOT MSVC)
ADD_DEFINITIONS("-USERVER_EXPORT")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
ENDIF()
ENDIF (NOT MSVC)
ADD_DEFINITIONS("\"-DSERVER_EXPORT=${DLLEXPORT}\"")


QT4_WRAP_CPP(qgis_mapserv_MOC_SRCS ${qgis_mapserv_MOC_HDRS})
@@ -52,7 +52,7 @@
#include <QtCore/QAbstractItemModel>
#include <QtCore/QStack>

class ModelTest : public QObject
class CORE_EXPORT ModelTest : public QObject
{
Q_OBJECT

0 comments on commit c1b520f

Please sign in to comment.
You can’t perform that action at this time.