Bladeren bron

Modules: Check for ARGC before using ARGV#

ARGV# could be defined from a parent scope.
Daniele E. Domenichelli 10 jaren geleden
bovenliggende
commit
a7631fc4e0

+ 5 - 1
Modules/BundleUtilities.cmake

@@ -457,7 +457,11 @@ endfunction()
 
 
 function(set_bundle_key_values keys_var context item exepath dirs copyflag)
-  set(rpaths "${ARGV6}")
+  if(ARGC GREATER 6)
+    set(rpaths "${ARGV6}")
+  else()
+    set(rpaths "")
+  endif()
   get_filename_component(item_name "${item}" NAME)
 
   get_item_key("${item}" key)

+ 72 - 18
Modules/DeployQt4.cmake

@@ -126,7 +126,10 @@ function(write_qt4_conf qt_conf_dir qt_conf_contents)
 endfunction()
 
 function(resolve_qt4_paths paths_var)
-        set(executable_path ${ARGV1})
+        unset(executable_path)
+        if(ARGC GREATER 1)
+                set(executable_path ${ARGV1})
+        endif()
 
         set(paths_resolved)
         foreach(path ${${paths_var}})
@@ -144,11 +147,26 @@ function(resolve_qt4_paths paths_var)
 endfunction()
 
 function(fixup_qt4_executable executable)
-        set(qtplugins ${ARGV1})
-        set(libs ${ARGV2})
-        set(dirs ${ARGV3})
-        set(plugins_dir ${ARGV4})
-        set(request_qt_conf ${ARGV5})
+        unset(qtplugins)
+        if(ARGC GREATER 1)
+                set(qtplugins ${ARGV1})
+        endif()
+        unset(libs)
+        if(ARGC GREATER 2)
+                set(libs ${ARGV2})
+        endif()
+        unset(dirs)
+        if(ARGC GREATER 3)
+                set(dirs ${ARGV3})
+        endif()
+        unset(plugins_dir)
+        if(ARGC GREATER 4)
+                set(plugins_dir ${ARGV4})
+        endif()
+        unset(request_qt_conf)
+        if(ARGC GREATER 5)
+                set(request_qt_conf ${ARGV5})
+        endif()
 
         message(STATUS "fixup_qt4_executable")
         message(STATUS "  executable='${executable}'")
@@ -169,7 +187,7 @@ function(fixup_qt4_executable executable)
                 set(qt_conf_dir "${executable}/Contents/Resources")
                 set(executable_path "${executable}")
                 set(write_qt_conf TRUE)
-                if(NOT plugins_dir)
+                if(NOT DEFINED plugins_dir)
                         set(plugins_dir "${DeployQt4_apple_plugins_dir}")
                 endif()
         else()
@@ -204,9 +222,19 @@ function(fixup_qt4_executable executable)
 endfunction()
 
 function(install_qt4_plugin_path plugin executable copy installed_plugin_path_var)
-        set(plugins_dir ${ARGV4})
-        set(component ${ARGV5})
-        set(configurations ${ARGV6})
+        unset(plugins_dir)
+        if(ARGC GREATER 4)
+                set(plugins_dir ${ARGV4})
+        endif()
+        unset(component)
+        if(ARGC GREATER 5)
+                set(component ${ARGV5})
+        endif()
+        unset(configurations)
+        if(ARGC GREATER 6)
+                set(configurations ${ARGV6})
+        endif()
+
         if(EXISTS "${plugin}")
                 if(APPLE)
                         if(NOT plugins_dir)
@@ -253,8 +281,15 @@ function(install_qt4_plugin_path plugin executable copy installed_plugin_path_va
 endfunction()
 
 function(install_qt4_plugin plugin executable copy installed_plugin_path_var)
-        set(plugins_dir ${ARGV4})
-        set(component ${ARGV5})
+        unset(plugins_dir)
+        if(ARGC GREATER 4)
+                set(plugins_dir ${ARGV4})
+        endif()
+        unset(component)
+        if(ARGC GREATER 5)
+                set(component ${ARGV5})
+        endif()
+
         if(EXISTS "${plugin}")
                 install_qt4_plugin_path("${plugin}" "${executable}" "${copy}" "${installed_plugin_path_var}" "${plugins_dir}" "${component}")
         else()
@@ -287,12 +322,31 @@ function(install_qt4_plugin plugin executable copy installed_plugin_path_var)
 endfunction()
 
 function(install_qt4_executable executable)
-        set(qtplugins ${ARGV1})
-        set(libs ${ARGV2})
-        set(dirs ${ARGV3})
-        set(plugins_dir ${ARGV4})
-        set(request_qt_conf ${ARGV5})
-        set(component ${ARGV6})
+        unset(qtplugins)
+        if(ARGC GREATER 1)
+                set(qtplugins ${ARGV1})
+        endif()
+        unset(libs)
+        if(ARGC GREATER 2)
+                set(libs ${ARGV2})
+        endif()
+        unset(dirs)
+        if(ARGC GREATER 3)
+                set(dirs ${ARGV3})
+        endif()
+        unset(plugins_dir)
+        if(ARGC GREATER 4)
+                set(plugins_dir ${ARGV4})
+        endif()
+        unset(request_qt_conf)
+        if(ARGC GREATER 5)
+                set(request_qt_conf ${ARGV5})
+        endif()
+        unset(component)
+        if(ARGC GREATER 6)
+                set(component ${ARGV6})
+        endif()
+
         if(QT_LIBRARY_DIR)
                 list(APPEND dirs "${QT_LIBRARY_DIR}")
         endif()

+ 1 - 1
Modules/ExternalProject.cmake

@@ -1360,7 +1360,7 @@ endfunction()
 
 function(ExternalProject_Add_StepTargets name)
   set(steps ${ARGN})
-  if("${ARGV1}" STREQUAL "NO_DEPENDS")
+  if(ARGC GREATER 1 AND "${ARGV1}" STREQUAL "NO_DEPENDS")
     set(no_deps 1)
     list(REMOVE_AT steps 0)
   endif()

+ 8 - 2
Modules/FeatureSummary.cmake

@@ -562,8 +562,14 @@ endfunction()
 # The stuff below is only kept for compatibility
 
 function(SET_PACKAGE_INFO _name _desc)
-  set(_url "${ARGV2}")
-  set(_purpose "${ARGV3}")
+  unset(_url)
+  unset(_purpose)
+  if(ARGC GREATER 2)
+    set(_url "${ARGV2}")
+  endif()
+  if(ARGC GREATER 3)
+    set(_purpose "${ARGV3}")
+  endif()
   set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
   if(NOT _url STREQUAL "")
     set_property(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_url}" )

+ 1 - 1
Modules/FindPkgConfig.cmake

@@ -143,7 +143,7 @@ endmacro()
 #  - _pkgconfig_add_extra_path(_extra_paths ENV VAR)
 function(_pkgconfig_add_extra_path _extra_paths_var _var)
   set(_is_env 0)
-  if(_var STREQUAL "ENV")
+  if(ARGC GREATER 2 AND _var STREQUAL "ENV")
     set(_var ${ARGV2})
     set(_is_env 1)
   endif()

+ 1 - 1
Modules/GenerateExportHeader.cmake

@@ -395,7 +395,7 @@ function(add_compiler_export_flags)
 
   # Either return the extra flags needed in the supplied argument, or to the
   # CMAKE_CXX_FLAGS if no argument is supplied.
-  if(ARGV0)
+  if(ARGC GREATER 0)
     set(${ARGV0} "${EXTRA_FLAGS}" PARENT_SCOPE)
   else()
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS}" PARENT_SCOPE)

+ 24 - 12
Modules/GetPrerequisites.cmake

@@ -330,7 +330,11 @@ endfunction()
 function(gp_resolve_item context item exepath dirs resolved_item_var)
   set(resolved 0)
   set(resolved_item "${item}")
-  set(rpaths "${ARGV5}")
+  if(ARGC GREATER 5)
+    set(rpaths "${ARGV5}")
+  else()
+    set(rpaths "")
+  endif()
 
   # Is it already resolved?
   #
@@ -481,7 +485,11 @@ endfunction()
 
 
 function(gp_resolved_file_type original_file file exepath dirs type_var)
-  set(rpaths "${ARGV5}")
+  if(ARGC GREATER 5)
+    set(rpaths "${ARGV5}")
+  else()
+    set(rpaths "")
+  endif()
   #message(STATUS "**")
 
   if(NOT IS_ABSOLUTE "${original_file}")
@@ -623,7 +631,11 @@ endfunction()
 function(get_prerequisites target prerequisites_var exclude_system recurse exepath dirs)
   set(verbose 0)
   set(eol_char "E")
-  set(rpaths "${ARGV6}")
+  if(ARGC GREATER 6)
+    set(rpaths "${ARGV6}")
+  else()
+    set(rpaths "")
+  endif()
 
   if(NOT IS_ABSOLUTE "${target}")
     message("warning: target '${target}' is not absolute...")
@@ -881,22 +893,22 @@ endfunction()
 
 
 function(list_prerequisites target)
-  if("${ARGV1}" STREQUAL "")
-    set(all 1)
-  else()
+  if(ARGC GREATER 1 AND NOT "${ARGV1}" STREQUAL "")
     set(all "${ARGV1}")
+  else()
+    set(all 1)
   endif()
 
-  if("${ARGV2}" STREQUAL "")
-    set(exclude_system 0)
-  else()
+  if(ARGC GREATER 2 AND NOT "${ARGV2}" STREQUAL "")
     set(exclude_system "${ARGV2}")
+  else()
+    set(exclude_system 0)
   endif()
 
-  if("${ARGV3}" STREQUAL "")
-    set(verbose 0)
-  else()
+  if(ARGC GREATER 3 AND NOT "${ARGV3}" STREQUAL "")
     set(verbose "${ARGV3}")
+  else()
+    set(verbose 0)
   endif()
 
   set(count 0)

+ 9 - 3
Modules/Qt4Macros.cmake

@@ -158,7 +158,7 @@ macro (QT4_GENERATE_MOC infile outfile )
      set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
    endif()
 
-   if ("x${ARGV2}" STREQUAL "xTARGET")
+   if (${ARGC} GREATER 3 AND "x${ARGV2}" STREQUAL "xTARGET")
       set(moc_target ${ARGV3})
    endif()
    QT4_CREATE_MOC_COMMAND(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}")
@@ -329,7 +329,10 @@ endmacro()
 macro(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
   get_filename_component(_infile ${_xml_file} ABSOLUTE)
 
-  set(_optionalBasename "${ARGV4}")
+  unset(_optionalBasename)
+  if(${ARGC} GREATER 4)
+    set(_optionalBasename "${ARGV4}")
+  endif()
   if (_optionalBasename)
     set(_basename ${_optionalBasename} )
   else ()
@@ -337,7 +340,10 @@ macro(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optional
     string(TOLOWER ${_basename} _basename)
   endif ()
 
-  set(_optionalClassName "${ARGV5}")
+  unset(_optionalClassName)
+  if(${ARGC} GREATER 5)
+    set(_optionalClassName "${ARGV5}")
+  endif()
   set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
   set(_impl   "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
   set(_moc    "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")