Skip to content

Commit

Permalink
Merge pull request #81 from traversaro/winsharedsupport
Browse files Browse the repository at this point in the history
Enable support for BUILD_SHARED_LIBS on Windows
  • Loading branch information
themarpe authored Jun 30, 2024
2 parents e0eddd9 + 54485ca commit 85c306c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set(XLINK_LIBUSB_LOCAL "" CACHE STRING "Path to local libub source to use instea
# Debug option
option(XLINK_LIBUSB_SYSTEM "Use system libusb library instead of Hunter" OFF)

# Specify exporting all symbols on Windows (WIP: shared library on windows doesn't yet work fully (eg logging))
# Specify exporting all symbols on Windows
if(WIN32 AND BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE BOOL "")
endif()
Expand Down Expand Up @@ -65,7 +65,10 @@ get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
set_target_properties(${TARGET_NAME} PROPERTIES DEBUG_POSTFIX "d")
endif()

# Define export header to support shared library on Windows
include(GenerateExportHeader)
generate_export_header(${TARGET_NAME}
EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}Export.h)
# Add dependencies
include(cmake/XLinkDependencies.cmake)

Expand Down Expand Up @@ -133,6 +136,7 @@ add_library(${TARGET_PUBLIC_NAME} INTERFACE)
target_include_directories(${TARGET_PUBLIC_NAME} INTERFACE
"$<INSTALL_INTERFACE:include>"
"$<BUILD_INTERFACE:${XLINK_INCLUDE}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)

# Link to headers (public, as itself also needs the headers)
Expand Down Expand Up @@ -243,6 +247,12 @@ install(
)
#Install include folder
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Install generated export header
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}Export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/XLink
)

# Install Hunter dependencies
if(XLINK_ENABLE_LIBUSB)
if(NOT XLINK_LIBUSB_LOCAL AND NOT XLINK_LIBUSB_SYSTEM)
Expand Down
6 changes: 4 additions & 2 deletions include/XLink/XLinkLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extern "C" {
#include <stdarg.h>
#include <inttypes.h>

#include "XLinkExport.h"

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
Expand Down Expand Up @@ -72,8 +74,8 @@ FUNCATTR_WEAK mvLog_t __attribute__ ((weak)) MVLOGLEVEL(MVLOG_UNIT_NAME) = MVLOG
#define UNIT_NAME_STR MVLOG_STR(MVLOG_UNIT_NAME)


extern mvLog_t MVLOGLEVEL(global);
extern mvLog_t MVLOGLEVEL(default);
extern XLINK_EXPORT mvLog_t MVLOGLEVEL(global);
extern XLINK_EXPORT mvLog_t MVLOGLEVEL(default);

int __attribute__ ((unused)) logprintf(mvLog_t curLogLvl, mvLog_t lvl, const char * func, const int line, const char * format, ...);

Expand Down

0 comments on commit 85c306c

Please sign in to comment.