Add testing of CMake exported targets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/.appveyor.yml b/.appveyor.yml
index fd488ba..d97a44e 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -52,7 +52,7 @@ build_script:
- ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" }
- md build
- cd build
- - cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DBUILD_TESTS=ON ..
+ - cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX="./install" ..
- cmake --build . --config "%CONFIGURATION%"
test_script:
@@ -60,4 +60,15 @@ test_script:
after_test:
- cmake --build . --config "%CONFIGURATION%" --target INSTALL
+ # Test also the use of dlfcn-win32 from an external CMake project
+ # Append the instllation directory of dlfcn-win32 to CMAKE_PREFIX_PATH to make sure that the CMake project is found
+ - set CMAKE_PREFIX_PATH=%APPVEYOR_BUILD_FOLDER%/build/install
+ # Append the bin installation directory of dlfcn-win32 to the path to make sure that .dll are found
+ - set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%/build/install/bin
+ - cd ../cmake-test
+ - md build
+ - cd build
+ - cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DBUILD_TESTS=ON ..
+ - cmake --build . --config "%CONFIGURATION%"
+ - ctest --output-on-failure --build-config "%CONFIGURATION%"
diff --git a/cmake-test/CMakeLists.txt b/cmake-test/CMakeLists.txt
new file mode 100644
index 0000000..532f2b8
--- /dev/null
+++ b/cmake-test/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Simple CMake project to test the use of dlfcn-win32
+# imported target. The test compiled is the same compiled
+# as part of the main dlfcn-win32 project
+
+cmake_minimum_required(VERSION 3.0)
+
+find_package(dlfcn-win32 REQUIRED)
+
+add_library(testdll SHARED ../testdll.c)
+set_target_properties(testdll PROPERTIES PREFIX "")
+add_executable(t_dlfcn ../test.c)
+target_link_libraries(t_dlfcn dlfcn-win32::dl)
+enable_testing()
+add_test(NAME t_dlfcn COMMAND t_dlfcn)
diff --git a/test.c b/test.c
index e7124ae..14523ad 100644
--- a/test.c
+++ b/test.c
@@ -24,6 +24,7 @@
#include <crtdbg.h>
#endif
#include <stdio.h>
+#include <string.h>
#include "dlfcn.h"
/* If these dlclose's fails, we don't care as the handles are going to be