Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: revise how we deal with symbol export and static builds #2912

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 29 additions & 34 deletions include/proj/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,38 @@ namespace proj {}
//! @cond Doxygen_Suppress

#ifndef PROJ_DLL
#ifdef PROJ_MSVC_DLL_EXPORT
#define PROJ_DLL __declspec(dllexport)
#elif defined(PROJ_MSVC_DLL_IMPORT)
#define PROJ_DLL __declspec(dllimport)
#elif defined(__GNUC__)
#define PROJ_DLL __attribute__((visibility("default")))
#else
#define PROJ_DLL
#endif
# if defined(_MSC_VER)
# ifdef PROJ_MSVC_DLL_EXPORT
# define PROJ_DLL __declspec(dllexport)
# else
# define PROJ_DLL __declspec(dllimport)
# endif
# elif defined(__GNUC__)
# define PROJ_DLL __attribute__ ((visibility("default")))
# else
# define PROJ_DLL
# endif
#endif

#ifndef PROJ_MSVC_DLL

#ifdef PROJ_MSVC_DLL_EXPORT
#define PROJ_MSVC_DLL PROJ_DLL
#define PROJ_GCC_DLL
#define PROJ_INTERNAL
#elif defined(PROJ_MSVC_DLL_IMPORT)
#define PROJ_MSVC_DLL PROJ_DLL
#define PROJ_GCC_DLL
#define PROJ_INTERNAL
#elif defined(__GNUC__)
#define PROJ_MSVC_DLL
#define PROJ_GCC_DLL PROJ_DLL
#if !defined(__MINGW32__)
#define PROJ_INTERNAL __attribute__((visibility("hidden")))
#else
#define PROJ_INTERNAL
#endif
#else
#define PROJ_MSVC_DLL
#define PROJ_GCC_DLL
#define PROJ_INTERNAL
#endif

#define PROJ_FOR_TEST PROJ_DLL

# if defined(_MSC_VER)
# define PROJ_MSVC_DLL PROJ_DLL
# define PROJ_GCC_DLL
# define PROJ_INTERNAL
# elif defined(__GNUC__)
# define PROJ_MSVC_DLL
# define PROJ_GCC_DLL PROJ_DLL
# if !defined(__MINGW32__)
# define PROJ_INTERNAL __attribute__((visibility("hidden")))
# else
# define PROJ_INTERNAL
# endif
# else
# define PROJ_MSVC_DLL
# define PROJ_GCC_DLL
# define PROJ_INTERNAL
# endif
# define PROJ_FOR_TEST PROJ_DLL
#endif

#include "nn.hpp"
Expand Down
4 changes: 0 additions & 4 deletions src/bin_cct.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ target_compile_options(cct PRIVATE ${PROJ_CXX_WARN_FLAGS})

install(TARGETS cct
DESTINATION ${BINDIR})

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(cct PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()
4 changes: 0 additions & 4 deletions src/bin_cs2cs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ target_compile_options(cs2cs PRIVATE ${PROJ_CXX_WARN_FLAGS})

install(TARGETS cs2cs
DESTINATION ${BINDIR})

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(cs2cs PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()
8 changes: 0 additions & 8 deletions src/bin_geod.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ target_compile_options(geod PRIVATE ${PROJ_CXX_WARN_FLAGS})
install(TARGETS geod
DESTINATION ${BINDIR})

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(geod PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()

# invgeod target: symlink or copy of geod executable

if(UNIX)
Expand Down Expand Up @@ -48,8 +44,4 @@ else()
install(TARGETS invgeod
DESTINATION ${BINDIR})

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(invgeod PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()

endif()
4 changes: 0 additions & 4 deletions src/bin_geodtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ target_compile_options(geodtest PRIVATE ${PROJ_CXX_WARN_FLAGS})

# Do not install, instead run as a test
add_test(NAME geodesic-test COMMAND geodtest)

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(geodtest PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()
4 changes: 0 additions & 4 deletions src/bin_gie.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ if(BUILD_GIE)
install(TARGETS gie
DESTINATION ${BINDIR})
endif()

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(gie PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()
8 changes: 0 additions & 8 deletions src/bin_proj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ target_compile_options(binproj PRIVATE ${PROJ_CXX_WARN_FLAGS})
install(TARGETS binproj
DESTINATION ${BINDIR})

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(binproj PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()

# invproj target: symlink or copy of proj executable

if(UNIX)
Expand Down Expand Up @@ -49,8 +45,4 @@ else()
install(TARGETS invproj
DESTINATION ${BINDIR})

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(invproj PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()

endif()
4 changes: 0 additions & 4 deletions src/bin_projinfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ target_compile_options(binprojinfo PRIVATE ${PROJ_CXX_WARN_FLAGS})
install(TARGETS binprojinfo
DESTINATION ${BINDIR})

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(binprojinfo PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()

if(CURL_ENABLED)
target_compile_definitions(binprojinfo PRIVATE -DCURL_ENABLED)
endif()
4 changes: 0 additions & 4 deletions src/bin_projsync.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ target_compile_options(bin_projsync PRIVATE ${PROJ_CXX_WARN_FLAGS})

install(TARGETS bin_projsync
DESTINATION ${BINDIR})

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(bin_projsync PRIVATE PROJ_MSVC_DLL_IMPORT=1)
endif()
9 changes: 6 additions & 3 deletions src/lib_proj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,12 @@ if(CURL_ENABLED)
$<$<CXX_COMPILER_ID:MSVC>:normaliz>)
endif()

if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(proj
PRIVATE PROJ_MSVC_DLL_EXPORT=1)
if(BUILD_SHARED_LIBS)
if(MSVC)
target_compile_definitions(proj PRIVATE PROJ_MSVC_DLL_EXPORT=1)
endif()
else()
target_compile_definitions(proj PUBLIC PROJ_DLL=)
endif()

##############################################
Expand Down
20 changes: 11 additions & 9 deletions src/proj.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ extern "C" {
/*! @cond Doxygen_Suppress */

#ifndef PROJ_DLL
#ifdef PROJ_MSVC_DLL_EXPORT
#define PROJ_DLL __declspec(dllexport)
#elif defined(PROJ_MSVC_DLL_IMPORT)
#define PROJ_DLL __declspec(dllimport)
#elif defined(__GNUC__)
#define PROJ_DLL __attribute__ ((visibility("default")))
#else
#define PROJ_DLL
#endif
# if defined(_MSC_VER)
# ifdef PROJ_MSVC_DLL_EXPORT
# define PROJ_DLL __declspec(dllexport)
# else
# define PROJ_DLL __declspec(dllimport)
# endif
# elif defined(__GNUC__)
# define PROJ_DLL __attribute__ ((visibility("default")))
# else
# define PROJ_DLL
# endif
#endif

#ifdef PROJ_SUPPRESS_DEPRECATION_MESSAGE
Expand Down
4 changes: 0 additions & 4 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ endif() # USE_EXTERNAL_GTEST
# Build PROJ unit tests
#

if(MSVC AND BUILD_SHARED_LIBS)
add_definitions(-DPROJ_MSVC_DLL_IMPORT=1)
endif()

include_directories(${PROJ_SOURCE_DIR}/include)
include_directories(${SQLITE3_INCLUDE_DIR})
# Add the directory containing proj_config.h
Expand Down