From 506090032a07f2f3a74a44d8c8774cbdd252c947 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 28 Sep 2024 14:45:53 +0200 Subject: WIP ExternalProject test --- mwe/dynlink/exec/CMakeLists.txt | 10 +++++++++- mwe/dynlink/exec/main.c | 3 ++- mwe/dynlink/lib/CMakeLists.txt | 16 +++++++++++++++- mwe/dynlink/lib/lib.c | 3 --- mwe/dynlink/lib/lib.h | 3 --- mwe/dynlink/lib/test.c | 3 +++ mwe/dynlink/lib/test.h | 3 +++ 7 files changed, 32 insertions(+), 9 deletions(-) delete mode 100644 mwe/dynlink/lib/lib.c delete mode 100644 mwe/dynlink/lib/lib.h create mode 100644 mwe/dynlink/lib/test.c create mode 100644 mwe/dynlink/lib/test.h diff --git a/mwe/dynlink/exec/CMakeLists.txt b/mwe/dynlink/exec/CMakeLists.txt index 5335f0f..465b45e 100644 --- a/mwe/dynlink/exec/CMakeLists.txt +++ b/mwe/dynlink/exec/CMakeLists.txt @@ -5,12 +5,20 @@ set(CMAKE_CXX_STANDARD 20) project(main C CXX) +add_executable(main main.c) + # Since we have the source code for the test library, we might as well let # CMake use it so it automatically picks up the interface headers and compiles # the library for us. The same can be achieved manually, but is more code. add_subdirectory(../lib test) -add_executable(main main.c) +# include(ExternalProject) +# ExternalProject_Add(test_ext +# SOURCE_DIR ../../lib +# CMAKE_ARGS -DCMAKE_INSTALL_PREFIX="${CMAKE_BINARY_DIR}/ext" +# ) +# add_dependencies(main test_ext) +# find_package(test REQUIRED) # Make sure ld.so (linux) looks in the same folder as the final executable for # the .so dependency diff --git a/mwe/dynlink/exec/main.c b/mwe/dynlink/exec/main.c index 2bbdc20..ea55feb 100644 --- a/mwe/dynlink/exec/main.c +++ b/mwe/dynlink/exec/main.c @@ -1,7 +1,8 @@ -#include +#include int main() { library_function(); return 0; } + diff --git a/mwe/dynlink/lib/CMakeLists.txt b/mwe/dynlink/lib/CMakeLists.txt index 2d15353..7efc91a 100644 --- a/mwe/dynlink/lib/CMakeLists.txt +++ b/mwe/dynlink/lib/CMakeLists.txt @@ -5,6 +5,20 @@ set(CMAKE_CXX_STANDARD 20) project(lib C CXX) -add_library(test SHARED lib.c) +add_library(test SHARED) + target_include_directories(test SYSTEM INTERFACE .) +target_sources(test PUBLIC + test.c +) + +target_sources(test PUBLIC FILE_SET HEADERS FILES + test.h +) + +install( + TARGETS test + FILE_SET HEADERS DESTINATION include +) + diff --git a/mwe/dynlink/lib/lib.c b/mwe/dynlink/lib/lib.c deleted file mode 100644 index c7a78e4..0000000 --- a/mwe/dynlink/lib/lib.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -void library_function() { printf("%s\n", __PRETTY_FUNCTION__); } diff --git a/mwe/dynlink/lib/lib.h b/mwe/dynlink/lib/lib.h deleted file mode 100644 index 093eadb..0000000 --- a/mwe/dynlink/lib/lib.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void library_function(); diff --git a/mwe/dynlink/lib/test.c b/mwe/dynlink/lib/test.c new file mode 100644 index 0000000..c7a78e4 --- /dev/null +++ b/mwe/dynlink/lib/test.c @@ -0,0 +1,3 @@ +#include + +void library_function() { printf("%s\n", __PRETTY_FUNCTION__); } diff --git a/mwe/dynlink/lib/test.h b/mwe/dynlink/lib/test.h new file mode 100644 index 0000000..093eadb --- /dev/null +++ b/mwe/dynlink/lib/test.h @@ -0,0 +1,3 @@ +#pragma once + +void library_function(); -- cgit v1.2.3