Skip to content

Commit 91f5b0c

Browse files
committed
Remove examples from primary build because they were relying on in-tree artifacts and thus were masking installation issues
1 parent 57f5e48 commit 91f5b0c

File tree

5 files changed

+55
-16
lines changed

5 files changed

+55
-16
lines changed

.github/workflows/cppcmake.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ jobs:
6262
-DCMAKE_INSTALL_PREFIX=${PWD}/install \
6363
-DLSL_UNITTESTS=ON \
6464
-DLSL_BENCHMARKS=ON \
65-
-DLSL_BUILD_EXAMPLES=ON \
6665
-DCPACK_PACKAGE_DIRECTORY=${PWD}/package \
6766
-Dlslgitrevision=${{ github.sha }} \
6867
-Dlslgitbranch=${{ github.ref }} \
@@ -71,6 +70,13 @@ jobs:
7170
echo ${PWD}
7271
- name: make
7372
run: cmake --build build --target install --config Release -j
73+
74+
- name: test install using examples
75+
run: |
76+
# Test that the in-tree install was successful by building the examples
77+
cmake -S examples -B examples/build -DLSL_INSTALL_ROOT=${PWD}/install -DCMAKE_INSTALL_PREFIX=examples/build/install -DLSL_COMFY_DEFAULTS=ON
78+
cmake --build examples/build --target install --config Release -j
79+
./examples/build/install/bin/HandleMetaData
7480
7581
- name: package
7682
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
# CLion
1414
.idea/
1515
/cmake-build-*/
16+
/examples/build*/

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ if(LSL_UNITTESTS)
2323
add_subdirectory(testing)
2424
endif()
2525

26-
if(LSL_BUILD_EXAMPLES)
27-
set(LSL_INSTALL_ROOT ${CMAKE_CURRENT_BINARY_DIR})
28-
add_subdirectory(examples)
29-
endif()
30-
3126
# Config for packaging
3227
# TODO: Config for packaging for the library itself is likely to diverge from config for packing applications. e.g.,
3328
# -> Optionally install to system directories

examples/CMakeLists.txt

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
cmake_minimum_required(VERSION 3.12)
1+
cmake_minimum_required(VERSION 3.23)
22
project(lslexamples
33
LANGUAGES C CXX
44
VERSION 0.2.0)
55
find_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+
)
1013
get_filename_component(LSL_PATH ${LSL_CONFIG} DIRECTORY)
1114
message(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)
2462
endfunction()
2563

2664
find_package(Threads)
@@ -46,4 +84,3 @@ addlslexample(SendStringMarkersC c)
4684
addlslexample(TestSyncWithoutData cpp)
4785

4886
target_link_libraries(TestSyncWithoutData PRIVATE Threads::Threads)
49-

examples/HandleMetaData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
4343
}
4444

4545
} catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
46-
std::cout << "Press any key to exit. " << std::endl;
47-
std::cin.get();
46+
// std::cout << "Press any key to exit. " << std::endl;
47+
// std::cin.get();
4848
return 0;
4949
}

0 commit comments

Comments
 (0)