Skip to content

Commit e7a0562

Browse files
committed
Fixup handling the .dll file for the examples.
1 parent 98b5d25 commit e7a0562

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

examples/CMakeLists.txt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ cmake_minimum_required(VERSION 3.23)
22
project(lslexamples
33
LANGUAGES C CXX
44
VERSION 0.2.0)
5+
6+
include(GNUInstallDirs)
7+
58
find_package(LSL REQUIRED
69
HINTS
710
${LSL_INSTALL_ROOT}
811
"${CMAKE_CURRENT_LIST_DIR}/../install" # GHA scripts default install directory
912
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release/install" # CLion default if using -DCMAKE_INSTALL_PREFIX=install
10-
"${CMAKE_CURRENT_LIST_DIR}/../out/x64-Release/install" # MSVC default if using -DCMAKE_INSTALL_PREFIX=install TODO: Check this
13+
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release-visual-studio/install" # CLion default if using VS compiler
14+
"${CMAKE_CURRENT_LIST_DIR}/../out/build/x64-Release/install" # MSVC default if using -DCMAKE_INSTALL_PREFIX=install
1115
PATH_SUFFIXES share/LSL
1216
)
1317
get_filename_component(LSL_PATH ${LSL_CONFIG} DIRECTORY)
@@ -50,15 +54,6 @@ function(addlslexample name extension)
5054
COMPONENT ${PROJECT_NAME}
5155
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
5256
)
53-
if(WIN32)
54-
# On Windows, we need to copy the DLLs to the same directory as the executable
55-
# if we wish to run the example without putting the DLLs in the PATH.
56-
install(
57-
FILES $<TARGET_FILE:LSL::lsl>
58-
DESTINATION ${CMAKE_INSTALL_BINDIR}
59-
COMPONENT ${PROJECT_NAME}
60-
)
61-
endif(WIN32)
6257
endfunction()
6358

6459
find_package(Threads)
@@ -84,3 +79,19 @@ addlslexample(SendStringMarkersC c)
8479
addlslexample(TestSyncWithoutData cpp)
8580

8681
target_link_libraries(TestSyncWithoutData PRIVATE Threads::Threads)
82+
83+
# Windows doesn't have RPATH so we put the dll into the same directory as the executable.
84+
if(WIN32)
85+
# For one of the targets, copy the lsl.dll into the build directory so we can debug the examples if needed.
86+
add_custom_command(TARGET HandleMetaData POST_BUILD
87+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
88+
"$<TARGET_FILE:LSL::lsl>"
89+
$<TARGET_FILE_DIR:HandleMetaData>
90+
COMMENT "Copying lsl.dll to examples build directory"
91+
)
92+
# Install the lsl.dll to the same directory as the executable.
93+
install(
94+
CODE "file(INSTALL DESTINATION \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\" TYPE SHARED_LIBRARY FILES \"$<TARGET_FILE:LSL::lsl>\")"
95+
COMPONENT ${PROJECT_NAME}
96+
)#install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different \"$<TARGET_FILE:LSL::lsl>\" \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\")")
97+
endif()

0 commit comments

Comments
 (0)