From 8b4c281377822f1289d8db884eb70efa022407f8 Mon Sep 17 00:00:00 2001 From: Siddharth Chandrasekaran Date: Thu, 21 Mar 2024 12:42:13 +0100 Subject: [PATCH] cmake: Fix MSVC OSDP_EXPORT macro issue Signed-off-by: Siddharth Chandrasekaran --- CMakeLists.txt | 4 +--- src/CMakeLists.txt | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c76db21..65f38d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,9 +26,7 @@ include(BuildType) include(GNUInstallDirs) ## Global settings -if(MSVC) - add_compile_options(/W4 /WX) -else() +if(NOT MSVC) add_compile_options(-Wall -Wextra) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 530bda4..d752c0c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -161,15 +161,6 @@ install( ARCHIVE DESTINATION ${LIBOSDP_LIBRARY_DIR} PUBLIC_HEADER DESTINATION include/libosdp ) - -# generate osdp_export.h for OSDP_EXPORT() macro -# must be placed after the target definitions. -include(GenerateExportHeader) -generate_export_header(${LIB_OSDP_STATIC} - BASE_NAME OSDP - EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/osdp_export.h -) - endif() # CONFIG_BUILD_STATIC ################################################ @@ -230,16 +221,35 @@ install( PUBLIC_HEADER DESTINATION include/libosdp ) -# generate osdp_export.h for OSDP_EXPORT() macro -# must be placed after the target definitions. -include(GenerateExportHeader) -generate_export_header(${LIB_OSDP_SHARED} - BASE_NAME OSDP - EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/osdp_export.h -) - endif() # CONFIG_BUILD_SHARED +if (MSVC) + # MSVC expects the function declation to match the definition. + # This requires osdp.h also have a lot of OSDP_EXPORT prefixes which + # looks ugly. So for now, we will just disable this entirely. + string(CONCAT EXPORT_CONTENT + "#ifndef OSDP_EXPORT_H\n" + "#define OSDP_EXPORT_H\n" + "\n" + "#define OSDP_EXPORT\n" + "#define OSDP_NO_EXPORT\n" + "#define OSDP_DEPRECATED_EXPORT\n" + "#endif" + ) + file( + GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/osdp_export.h + CONTENT "${EXPORT_CONTENT}" + ) +else() + # generate osdp_export.h for OSDP_EXPORT macro + # must be placed after the target definitions. + include(GenerateExportHeader) + generate_export_header(${LIB_TARGET} + BASE_NAME OSDP + EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/osdp_export.h + ) +endif() # MSVC + # pkg-config file configure_file( ${PROJECT_SOURCE_DIR}/misc/libosdp.pc.in