Browse Source

Refactor: Replace CMAKE_CURRENT_LIST_DIR with CMAKE_CURRENT_FUNCTION_LIST_DIR

Some modules define an intermediate global scope visible variables
to access "resource" files from functions.
Now these variables could be eliminated.
Alex Turbov 5 years ago
parent
commit
24fdd51f45

+ 1 - 3
Modules/AndroidTestUtilities.cmake

@@ -76,8 +76,6 @@ Module Functions
 
 include(${CMAKE_CURRENT_LIST_DIR}/ExternalData.cmake)
 
-set(_AndroidTestUtilities_SELF_DIR "${CMAKE_CURRENT_LIST_DIR}")
-
 # The parameters to this function should be set to the list of directories,
 # files, and libraries that need to be installed prior to testing.
 function(android_add_test_data test_name)
@@ -159,6 +157,6 @@ function(android_add_test_data test_name)
       "-Darg_files=${processed_FILES}"
       "-Darg_libs=${AST_LIBS}"
       "-Darg_src_dir=${CMAKE_CURRENT_SOURCE_DIR}"
-      -P ${_AndroidTestUtilities_SELF_DIR}/AndroidTestUtilities/PushToAndroidDevice.cmake)
+      -P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/AndroidTestUtilities/PushToAndroidDevice.cmake)
   endif()
 endfunction()

+ 2 - 3
Modules/CMakeAddFortranSubdirectory.cmake

@@ -43,7 +43,6 @@ future version that supports installation of the external project
 binaries during ``make install``.
 #]=======================================================================]
 
-set(_MS_MINGW_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
 include(CheckLanguage)
 include(ExternalProject)
 
@@ -87,11 +86,11 @@ function(_setup_mingw_config_and_build source_dir build_dir)
   file(TO_NATIVE_PATH "${MINGW_PATH}" MINGW_PATH)
   string(REPLACE "\\" "\\\\" MINGW_PATH "${MINGW_PATH}")
   configure_file(
-    ${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/config_mingw.cmake.in
+    ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/CMakeAddFortranSubdirectory/config_mingw.cmake.in
     ${build_dir}/config_mingw.cmake
     @ONLY)
   configure_file(
-    ${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/build_mingw.cmake.in
+    ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/CMakeAddFortranSubdirectory/build_mingw.cmake.in
     ${build_dir}/build_mingw.cmake
     @ONLY)
 endfunction()

+ 1 - 2
Modules/DeployQt4.cmake

@@ -106,7 +106,6 @@ and plugin installation.  See documentation of FIXUP_QT4_BUNDLE.
 # The functions defined in this file depend on the fixup_bundle function
 # (and others) found in BundleUtilities.cmake
 
-set(DeployQt4_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")
 set(DeployQt4_apple_plugins_dir "PlugIns")
 
 function(write_qt4_conf qt_conf_dir qt_conf_contents)
@@ -392,7 +391,7 @@ function(install_qt4_executable executable)
   resolve_qt4_paths(libs "")
 
   install(CODE
-"include(\"${DeployQt4_cmake_dir}/DeployQt4.cmake\")
+"include(\"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/DeployQt4.cmake\")
 set(BU_CHMOD_BUNDLE_ITEMS TRUE)
 FIXUP_QT4_EXECUTABLE(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${executable}\" \"\" \"${libs}\" \"${dirs}\" \"${plugins_dir}\" \"${request_qt_conf}\")"
           ${component}

+ 1 - 4
Modules/FetchContent.cmake

@@ -596,9 +596,6 @@ current working directory.
 
 #]=======================================================================]
 
-
-set(__FetchContent_privateDir "${CMAKE_CURRENT_LIST_DIR}/FetchContent")
-
 #=======================================================================
 # Recording and retrieving content details for later population
 #=======================================================================
@@ -888,7 +885,7 @@ function(__FetchContent_directPopulate contentName)
   # anything to be updated, so extra rebuilds of the project won't occur.
   # Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
   # has this set to something not findable on the PATH.
-  configure_file("${__FetchContent_privateDir}/CMakeLists.cmake.in"
+  configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/FetchContent/CMakeLists.cmake.in"
                  "${ARG_SUBBUILD_DIR}/CMakeLists.txt")
   execute_process(
     COMMAND ${CMAKE_COMMAND} ${generatorOpts} .

+ 1 - 2
Modules/UseJava.cmake

@@ -405,7 +405,6 @@ endfunction()
 
 # define helper scripts
 set(_JAVA_EXPORT_TARGETS_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/javaTargets.cmake.in)
-set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake)
 set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake)
 
 function(add_jar _TARGET_NAME)
@@ -627,7 +626,7 @@ function(add_jar _TARGET_NAME)
             COMMAND ${CMAKE_COMMAND}
                 -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH}
                 -DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}"
-                -P ${_JAVA_CLASS_FILELIST_SCRIPT}
+                -P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/UseJavaClassFilelist.cmake
             DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
         )