Commit d22f7719cb6a610be6cc20cbfbb79698177360cd

Silvio 2017-03-05T16:48:00

Add testing of CMake exported targets

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