Sfoglia il codice sorgente

Do not append non-existent directory to "*_{INCLUDE,LIBRARY}_DIRS" variables

This is particularly useful when building against library that are not
always defining a "<project_name>_LIBRARY_DIRS" variable. This commit
avoids appending a variable name to the list of possible directories
that should be considered.

For example, within ITKv4, the variable ITK_LIBRARY_DIRS is not
always set. See here for more details: https://issues.itk.org/jira/browse/ITK-3026
Jean-Christophe Fillion-Robin 12 anni fa
parent
commit
f935c22cff
1 ha cambiato i file con 26 aggiunte e 14 eliminazioni
  1. 26 14
      CMakeLists.txt

+ 26 - 14
CMakeLists.txt

@@ -876,21 +876,27 @@ foreach(_external_target ${EXTERNAL_TARGETS})
 endforeach()
 
 foreach(_external_target ${EXTERNAL_TARGETS})
-  #set(_package_name ${${_external_target}_FIND_PACKAGE_CMD})
-  #if("${_package_name}" STREQUAL "")
-  #  set(_package_name ${_external_target})
-  #endif()
+  set(_package_name ${${_external_target}_FIND_PACKAGE_CMD})
+  if("${_package_name}" STREQUAL "")
+    set(_package_name ${_external_target})
+  endif()
   if(${_external_target}_INCLUDE_DIRS)
     #message("[${_package_name}] Resolving include variables: ${${_external_target}_INCLUDE_DIRS}")
     set(_updated_include_dirs)
     foreach(_include_variable ${${_external_target}_INCLUDE_DIRS})
+      set(_expanded_include_variable ${_include_variable})
       if(${_include_variable})
-        #message("[${_package_name}] Substituting [${_include_variable}] with [${${_include_variable}}]")
-        list(APPEND _updated_include_dirs ${${_include_variable}})
-      else()
-        #message("[${_package_name}] Appending ${${_include_variable}}")
-        list(APPEND _updated_include_dirs ${_include_variable})
+        #message("[${_package_name}] Expanding [${_include_variable}] into [${${_include_variable}}]")
+        set(_expanded_include_variable ${${_include_variable}})
       endif()
+      foreach(_include_dir ${_expanded_include_variable})
+        if(EXISTS ${_include_dir})
+          #message("[${_package_name}] Appending ${_include_dir}")
+          list(APPEND _updated_include_dirs ${_include_dir})
+        else()
+          message(STATUS "[${_package_name}] Skipping nonexistent include directory or not set variable [${_include_dir}]")
+        endif()
+      endforeach()
       #message("[${_package_name}] New dirs: ${_updated_include_dirs}")
     endforeach()
     set(${_external_target}_INCLUDE_DIRS ${_updated_include_dirs})
@@ -900,13 +906,19 @@ foreach(_external_target ${EXTERNAL_TARGETS})
     #message("[${_package_name}] Resolving library variables: ${${_external_target}_LIBRARY_DIRS}")
     set(_updated_library_dirs)
     foreach(_library_variable ${${_external_target}_LIBRARY_DIRS})
+      set(_expanded_library_variable ${_library_variable})
       if(${_library_variable})
-        #message("[${_package_name}] Substituting [${_library_variable}] with [${${_library_variable}}]")
-        list(APPEND _updated_library_dirs ${${_library_variable}})
-      else()
-        #message("[${_package_name}] Appending ${_library_variable}")
-        list(APPEND _updated_library_dirs ${_library_variable})
+        #message("[${_package_name}] Expanding [${_library_variable}] into [${${_library_variable}}]")
+        set(_expanded_library_variable ${${_library_variable}})
       endif()
+      foreach(_library_dir ${_expanded_library_variable})
+        if(EXISTS ${_library_dir})
+          #message("[${_package_name}] Appending ${_library_dir}")
+          list(APPEND _updated_library_dirs ${_library_dir})
+        else()
+          message(STATUS "[${_package_name}] Skipping nonexistent library directory or not set variable [${_library_dir}]")
+        endif()
+      endforeach()
       #message("[${_package_name}] New dirs: ${_updated_library_dirs}")
     endforeach()
     set(${_external_target}_LIBRARY_DIRS ${_updated_library_dirs})