From 9a36b15d66c5e340cd8695415ce5867ad07ee2bb Mon Sep 17 00:00:00 2001
From: Volker Enderlein <volkerenderlein@hotmail.com>
Date: Sun, 8 Mar 2020 14:24:29 +0100
Subject: [PATCH] Partially incorporating coin4.0.0a-patch from gentoo

---
 CMakeLists.txt | 63 ++++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 30 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 755bd9d59..d23f5bc0e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,8 +1,3 @@
-if (POLICY  CMP0054)
-  # CMake version 3.14.5 warns when the policy is not set and uses OLD behaviour
-  cmake_policy(SET CMP0054 NEW)
-endif()
-
 cmake_minimum_required(VERSION 3.0)
 
 set(COIN_MAJOR_VERSION 4)
@@ -22,6 +17,11 @@ math(EXPR COIN_SO_VERSION ${PROJECT_VERSION_MAJOR}*20)
 set(PROJECT_DESCRIPTION   "A high-level 3D visualization library with Open Inventor 2.1 API")
 # ############################################################################
 
+if(POLICY CMP0054)
+  # CMake version 3.14.5 warns when the policy is not set and uses OLD behaviour
+  cmake_policy(SET CMP0054 NEW)
+endif()
+
 if(POLICY CMP0072)
   # get rid of OpenGL GLVND warning from CMake 3.11
   cmake_policy(SET CMP0072 NEW)
@@ -103,8 +103,8 @@ cmake_dependent_option(COIN_BUILD_MAC_AGL "Build for AGL on Mac OS X when ON. De
 
 report_prepare(
   COIN_BUILD_SHARED_LIBS
-  COIN_BUILD_TESTS 
-  COIN_BUILD_DOCUMENTATION 
+  COIN_BUILD_TESTS
+  COIN_BUILD_DOCUMENTATION
   COIN_BUILD_INTERNAL_DOCUMENTATION
   COIN_BUILD_DOCUMENTATION_MAN
   COIN_BUILD_DOCUMENTATION_QTHELP
@@ -113,29 +113,29 @@ report_prepare(
   HAVE_VRML97
   COIN_HAVE_JAVASCRIPT
   HAVE_NODEKITS
-  HAVE_DRAGGERS 
-  HAVE_MANIPULATORS 
-  HAVE_SOUND 
+  HAVE_DRAGGERS
+  HAVE_MANIPULATORS
+  HAVE_SOUND
   HAVE_3DS_IMPORT_CAPABILITIES
   USE_EXTERNAL_EXPAT
-  USE_EXCEPTIONS 
-  USE_SUPERGLU 
-  FONTCONFIG_RUNTIME_LINKING   
-  FREETYPE_RUNTIME_LINKING     
-  LIBBZIP2_RUNTIME_LINKING     
-  OPENAL_RUNTIME_LINKING       
-  SIMAGE_RUNTIME_LINKING       
-  ZLIB_RUNTIME_LINKING         
-  GLU_RUNTIME_LINKING          
-  SPIDERMONKEY_RUNTIME_LINKING 
-  HAVE_MULTIPLE_VERSION 
+  USE_EXCEPTIONS
+  USE_SUPERGLU
+  FONTCONFIG_RUNTIME_LINKING
+  FREETYPE_RUNTIME_LINKING
+  LIBBZIP2_RUNTIME_LINKING
+  OPENAL_RUNTIME_LINKING
+  SIMAGE_RUNTIME_LINKING
+  ZLIB_RUNTIME_LINKING
+  GLU_RUNTIME_LINKING
+  SPIDERMONKEY_RUNTIME_LINKING
+  HAVE_MULTIPLE_VERSION
   IF_APPLE
-    COIN_BUILD_MAC_FRAMEWORK 
-    COIN_BUILD_MAC_X11 
-    COIN_BUILD_MAC_AGL 
+    COIN_BUILD_MAC_FRAMEWORK
+    COIN_BUILD_MAC_X11
+    COIN_BUILD_MAC_AGL
   IF_MSVC
     COIN_BUILD_MSVC_STATIC_RUNTIME
-    COIN_BUILD_SINGLE_LIB 
+    COIN_BUILD_SINGLE_LIB
     MSVC_VERSION
     COIN_BUILD_MSVC_MP
 )
@@ -147,8 +147,8 @@ if(HAVE_MULTIPLE_VERSION)
     CMAKE_INSTALL_DATADIR
     CMAKE_INSTALL_FULL_DATADIR
     CMAKE_INSTALL_INCLUDEDIR
-    CMAKE_INSTALL_FULL_INCLUDEDIR 
-    CMAKE_INSTALL_DOCDIR 
+    CMAKE_INSTALL_FULL_INCLUDEDIR
+    CMAKE_INSTALL_DOCDIR
     CMAKE_INSTALL_FULL_DOCDIR
   )
 else()
@@ -534,9 +534,12 @@ else()
   if(HAVE_MACH_O_DYLD_H)
     check_symbol_exists(NSLookupAndBindSymbol mach-o/dyld.h HAVE_DYLD_RUNTIME_BINDING)
   endif()
-  check_library_exists(dl dlopen "" HAVE_DL_LIB)
-  if(HAVE_DL_LIB)
-    check_include_file(dlfcn.h HAVE_DLFCN_H)
+  # On FreeBSD, NetBSD and OpenBSD there is no libdl, as the required
+  # functionality is already built into libc. So use ${CMAKE_DL_LIBS} instead.
+  check_include_file(dlfcn.h HAVE_DLFCN_H)
+  if(HAVE_DLFCN_H)
+    set(HAVE_DL_LIB 1)
+    list(APPEND COIN_TARGET_LINK_LIBRARIES ${CMAKE_DL_LIBS})
   endif()
   check_library_exists(dld shl_load "" HAVE_DLD_LIB)
 endif()
-- 
2.26.2

