From 213e0d993ffed5f5ed9e3abf85fb4c9de0e7454d Mon Sep 17 00:00:00 2001
From: Michael Kuron <mkuron@icp.uni-stuttgart.de>
Date: Wed, 13 Feb 2019 12:46:43 +0100
Subject: [PATCH] Call target_link_libraries with PUBLIC keyword if necessary

---
 CMakeLists.txt                             | 5 +++++
 apps/pythonmodule/CMakeLists.txt           | 2 +-
 cmake/waLBerlaFunctions.cmake              | 2 +-
 cmake/waLBerlaModuleDependencySystem.cmake | 4 ++--
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 90049a6d5..4d67aa978 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,6 +129,11 @@ list( APPEND WALBERLA_MODULE_DIRS "${walberla_SOURCE_DIR}/src" "${walberla_SOURC
 list( REMOVE_DUPLICATES  WALBERLA_MODULE_DIRS )
 set ( WALBERLA_MODULE_DIRS  ${WALBERLA_MODULE_DIRS} CACHE INTERNAL "All folders that contain modules or tests" )
 
+# target_link_libraries needs to called with keywords everywhere if it is called with keywords once
+if( DEFINED CUDA_LINK_LIBRARIES_KEYWORD AND NOT CUDA_LINK_LIBRARIES_KEYWORD STREQUAL "" )
+    set( WALBERLA_LINK_LIBRARIES_KEYWORD PUBLIC )
+endif()
+
 ############################################################################################################################
 
 
diff --git a/apps/pythonmodule/CMakeLists.txt b/apps/pythonmodule/CMakeLists.txt
index e6ab8af9d..820784e2b 100644
--- a/apps/pythonmodule/CMakeLists.txt
+++ b/apps/pythonmodule/CMakeLists.txt
@@ -26,7 +26,7 @@ if ( WALBERLA_BUILD_WITH_PYTHON_MODULE )
         add_library( walberla_cpp SHARED PythonModule.cpp )
     endif()
 
-    target_link_libraries( walberla_cpp ${pythonModules} ${SERVICE_LIBS}  )
+    target_link_libraries( walberla_cpp ${WALBERLA_LINK_LIBRARIES_KEYWORD} ${pythonModules} ${SERVICE_LIBS}  )
     set_target_properties( walberla_cpp PROPERTIES PREFIX "")
     if ( APPLE )
        set_target_properties( walberla_cpp PROPERTIES SUFFIX ".so")
diff --git a/cmake/waLBerlaFunctions.cmake b/cmake/waLBerlaFunctions.cmake
index d62c6824b..da1b0b20d 100644
--- a/cmake/waLBerlaFunctions.cmake
+++ b/cmake/waLBerlaFunctions.cmake
@@ -228,7 +228,7 @@ function ( waLBerla_add_executable )
     set_source_files_properties( ${generatedSourceFiles} PROPERTIES GENERATED TRUE )
 
     target_link_modules  ( ${ARG_NAME} ${ARG_DEPENDS}  )
-    target_link_libraries( ${ARG_NAME} ${SERVICE_LIBS} )
+    target_link_libraries( ${ARG_NAME} ${WALBERLA_LINK_LIBRARIES_KEYWORD} ${SERVICE_LIBS} )
     set_property( TARGET ${ARG_NAME} PROPERTY CXX_STANDARD 14 )
 
     if( WALBERLA_GROUP_PROJECTS )
diff --git a/cmake/waLBerlaModuleDependencySystem.cmake b/cmake/waLBerlaModuleDependencySystem.cmake
index 45f7dbdc7..b955d81f4 100644
--- a/cmake/waLBerlaModuleDependencySystem.cmake
+++ b/cmake/waLBerlaModuleDependencySystem.cmake
@@ -31,7 +31,7 @@
 # This mechanism is just for convenience, one can simply compile an application that uses walberla modules
 # by standard cmake mechanisms:
 #  add_executable ( myApp  ${mySourceFiles} )
-#  target_link_libraries ( myApp  walberlaModule1 core-field  lbm-boundary ) 
+#  target_link_libraries ( myApp  ${WALBERLA_LINK_LIBRARIES_KEYWORD} walberlaModule1 core-field  lbm-boundary ) 
 # The difference here is that all transitively depending modules also have to be specified manually.
 # i.e. assume core-field depends on core-stencil, then core-stencil has to be added by hand. 
 # If you use waLBerla_add_executable , these dependent modules are added automatically.
@@ -202,7 +202,7 @@ function ( target_link_modules target )
         if( TARGET ${libraryName} ) 
      	   get_target_property( target_type ${libraryName} TYPE ) 
      	   if( ${target_type} MATCHES LIBRARY ) 
-     	      target_link_libraries( ${target} ${libraryName} )
+     	      target_link_libraries( ${target} ${WALBERLA_LINK_LIBRARIES_KEYWORD} ${libraryName} )
      	   endif( )                    
      	endif( ) 
     endforeach()
-- 
GitLab