From bce1907f6971274eae40585afce7cf9117f277aa Mon Sep 17 00:00:00 2001
From: Felix Ramold <felix.ramold@kuka.com>
Date: Tue, 24 Apr 2018 15:55:04 +0200
Subject: [PATCH] Correct disabling of the plugin feature

Dont build plugin test or subdirectories if the dynamic loading feature is not
supported by the platform.
---
 cmake/PlatformChecks.cmake          | 10 ++++++++++
 examples/CMakeLists.txt             |  5 ++++-
 examples/cppunittest/CMakeLists.txt | 17 ++++++++++-------
 examples/simple/CMakeLists.txt      | 16 ++++++++++------
 src/CMakeLists.txt                  |  5 ++++-
 5 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/cmake/PlatformChecks.cmake b/cmake/PlatformChecks.cmake
index d446586..49044f3 100644
--- a/cmake/PlatformChecks.cmake
+++ b/cmake/PlatformChecks.cmake
@@ -39,11 +39,21 @@ if(CPPUNIT_HAVE_UNIX_SHL_LOADER)
     list(APPEND CPPUNIT_COMMON_LIBS "dld")
 endif()
 
+# from SelectDllLoader.h
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows"
+    AND NOT BEOS  # see <cmakedir>\share\cmake-x.y\Modules\Platform\BeOS.cmake
+    AND NOT CPPUNIT_HAVE_SHL_LOAD
+    AND NOT CPPUNIT_HAVE_LIBDL
+)
+    set(CPPUNIT_NO_TESTPLUGIN 1)
+endif()
+
 # C function checks
 include(CheckFunctionExists)
 check_function_exists(finite CPPUNIT_HAVE_FINITE)
 check_function_exists(_finite CPPUNIT_HAVE__FINITE)
 
+
 # C symbol checks
 include(CheckSymbolExists)
 if(CPPUNIT_HAVE_MATH_H)
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 29e91e1..c15fd2e 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,7 +1,10 @@
 add_subdirectory(cppunittest)
 add_subdirectory(hierarchy)
 add_subdirectory(simple)
-add_subdirectory(DumperPlugIn)
+
+if(NOT CPPUNIT_NO_TESTPLUGIN)
+    add_subdirectory(DumperPlugIn)
+endif()
 
 if(CPPUNIT_BUILD_QT_TESTRUNNER)
     add_subdirectory(qt)
diff --git a/examples/cppunittest/CMakeLists.txt b/examples/cppunittest/CMakeLists.txt
index f41d46e..ad870d3 100644
--- a/examples/cppunittest/CMakeLists.txt
+++ b/examples/cppunittest/CMakeLists.txt
@@ -41,13 +41,16 @@ if(CPPUNIT_BUILD_TESTING)
     add_test(NAME cppunit-test-bin COMMAND cppunit-test-bin)
 endif()
 
-# Create the test plugin
-add_library(cppunit-test-plugin MODULE CppUnitTestPlugIn.cpp $<TARGET_OBJECTS:cppunit-test-objlib>)
-target_link_libraries(cppunit-test-plugin cppunit)
-
 # Create install target
 install(TARGETS cppunit-test-bin
-    DESTINATION share/${CPPUNIT_VERSION}/examples COMPONENT examples)
+   DESTINATION share/${CPPUNIT_VERSION}/examples COMPONENT examples)
+
+if(NOT CPPUNIT_NO_TESTPLUGIN)
+    # Create the test plugin
+    add_library(cppunit-test-plugin MODULE CppUnitTestPlugIn.cpp $<TARGET_OBJECTS:cppunit-test-objlib>)
+    target_link_libraries(cppunit-test-plugin cppunit)
 
-install(TARGETS cppunit-test-plugin
-     DESTINATION share/${CPPUNIT_VERSION}/examples COMPONENT examples)
+    # Create install target
+    install(TARGETS cppunit-test-plugin
+        DESTINATION share/${CPPUNIT_VERSION}/examples COMPONENT examples)
+endif()
diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt
index 22f0508..cc7167b 100644
--- a/examples/simple/CMakeLists.txt
+++ b/examples/simple/CMakeLists.txt
@@ -6,13 +6,17 @@ set(cppunit-simple_SOURCES
 add_executable(cppunit-simple-bin Main.cpp ${cppunit-simple_SOURCES})
 target_link_libraries(cppunit-simple-bin cppunit)
 
-# Create the test plugin
-add_library(cppunit-simple-plugin MODULE SimplePlugIn.cpp ${cppunit-simple_SOURCES})
-target_link_libraries(cppunit-simple-plugin cppunit)
-
 # Create install target
 install(TARGETS cppunit-simple-bin
     DESTINATION share/${CPPUNIT_VERSION}/examples COMPONENT examples)
 
-install(TARGETS cppunit-simple-plugin
-     DESTINATION share/${CPPUNIT_VERSION}/examples COMPONENT examples)
+    if(NOT CPPUNIT_NO_TESTPLUGIN)
+    # Create the test plugin
+    add_library(cppunit-simple-plugin MODULE SimplePlugIn.cpp ${cppunit-simple_SOURCES})
+    target_link_libraries(cppunit-simple-plugin cppunit)
+
+    # Create install target
+    install(TARGETS cppunit-simple-plugin
+        DESTINATION share/${CPPUNIT_VERSION}/examples COMPONENT examples)
+endif()
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fea7014..0f14ce3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,8 @@
 add_subdirectory(cppunit)
-add_subdirectory(DllPlugInTester)
+
+if(NOT CPPUNIT_NO_TESTPLUGIN)
+   add_subdirectory(DllPlugInTester)
+endif()
 
 if(CPPUNIT_BUILD_QT_TESTRUNNER)
     add_subdirectory(qttestrunner)
-- 
2.9.3.windows.2

