From bd078e12bd79278037d6a805a0d9302b7dce8931 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 24 Mar 2023 03:29:46 +0100 Subject: [PATCH] cmake: automatic exports macro tidy-up (#875) In a recent CMake update I left the original CMake EXPORTS macro unchanged (`libssh2_EXPORTS`) for compatibility. However, that macro was also recently added [1] and not present in an official release yet, so we might as well just use the new native one instead (`libssh2_shared_EXPORTS`), defined by CMake automatically. This way we don't need to define the old macro manually. CMake forms this macro from the lib's internal name as defined in `add_library()` by appending `_EXPORTS`. That target name changed from `libssh2` to `libssh2_shared` after introducing dual shared + static builds in the recent update. If we're here, add a new, stable, build-tool agnostic macro with the same effect, for non-CMake use: `LIBSSH2_EXPORTS` [1] 1f0fe7443a1ecddd320f2c693607b2afee9bbe2f (2021-10-26) Follow-up to 4e2580628dd1f8dc51ac65ac747ebcf0e93fa3d1 --- include/libssh2.h | 3 ++- src/CMakeLists.txt | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index f7c95cbc..98a31a43 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -100,7 +100,8 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API # ifdef WIN32 -# if defined(_WINDLL) || defined(libssh2_EXPORTS) +# if defined(LIBSSH2_EXPORTS) || \ + defined(_WINDLL) || defined(libssh2_shared_EXPORTS) # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) # else diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77a1b60e..b98549d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -396,7 +396,6 @@ if(BUILD_SHARED_LIBS) add_library(libssh2_shared SHARED ${SOURCES}) if(WIN32) set_property(TARGET libssh2_shared APPEND PROPERTY SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) - target_compile_definitions(libssh2_shared PRIVATE libssh2_EXPORTS) endif() target_compile_definitions(libssh2_shared PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) target_link_libraries(libssh2_shared PRIVATE ${LIBRARIES})