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

Enable support for BUILD_SHARED_LIBS on Windows #81

Merged
merged 1 commit into from
Jun 30, 2024
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
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
Loading