1- cmake_minimum_required (VERSION 3.12 )
1+ cmake_minimum_required (VERSION 3.23 )
22project (lslexamples
33 LANGUAGES C CXX
44 VERSION 0.2.0)
55find_package (LSL REQUIRED
6- HINTS ${LSL_INSTALL_ROOT}
7- "${CMAKE_CURRENT_LIST_DIR} /../build"
8- "${CMAKE_CURRENT_LIST_DIR} /../out/x64-Release"
9- PATH_SUFFIXES share/LSL)
6+ HINTS
7+ ${LSL_INSTALL_ROOT}
8+ "${CMAKE_CURRENT_LIST_DIR} /../install" # GHA scripts default install directory
9+ "${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
11+ PATH_SUFFIXES share/LSL
12+ )
1013get_filename_component (LSL_PATH ${LSL_CONFIG} DIRECTORY )
1114message (STATUS "Found LSL lib in ${LSL_PATH} " )
12- message (STATUS "LSL BIN DIR: ${liblsl_BINARY_DIR} & ${LIBLSL_BINARY_DIR} " )
15+
16+ # Include the LSLCMake.cmake file, just for testing.
17+ # This doesn't do much for us now that we don't use installLSLApp() anymore.
18+ include ("${LSL_PATH} /LSLCMake.cmake" )
1319
1420# convenience function to add an example file
1521# this creates a target, links the necessary libraries and
@@ -20,7 +26,39 @@ function(addlslexample name extension)
2026 )
2127 target_link_libraries (${name} PRIVATE LSL::lsl)
2228 target_compile_features (${name} PRIVATE cxx_constexpr)
23- installLSLApp(${name} )
29+
30+ # Set RPATH properties for macOS and Linux
31+ set_target_properties (${name} PROPERTIES
32+ INSTALL_RPATH_USE_LINK_PATH TRUE
33+ BUILD_WITH_INSTALL_RPATH FALSE
34+ )
35+
36+ # One might also want to do the following, to give the option of copying the
37+ # LSL library to the same directory or install tree as the executable.
38+ # However, this is not necessary for the examples, as they are not intended to be relocated.
39+ # if(APPLE)
40+ # set_target_properties(${name} PROPERTIES
41+ # INSTALL_RPATH "@loader_path;@loader_path/../lib"
42+ # )
43+ # elseif(UNIX)
44+ # set_target_properties(${name} PROPERTIES
45+ # INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib"
46+ # )
47+ # endif()
48+
49+ install (TARGETS ${name}
50+ COMPONENT ${PROJECT_NAME}
51+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
52+ )
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 )
2462endfunction ()
2563
2664find_package (Threads)
@@ -46,4 +84,3 @@ addlslexample(SendStringMarkersC c)
4684addlslexample(TestSyncWithoutData cpp)
4785
4886target_link_libraries (TestSyncWithoutData PRIVATE Threads::Threads)
49-
0 commit comments