Skip to content

Commit

Permalink
cmake: Fix MSVC OSDP_EXPORT macro issue
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Mar 21, 2024
1 parent 3a84205 commit 8b4c281
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
44 changes: 27 additions & 17 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

################################################
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b4c281

Please sign in to comment.