Reviewers: Ian Ni-Lewis (Google)
CL:
https://codereview.chromium.org/1409753003/
Description:
Change CMAKE_SOURCE_DIR to CMAKE_CURRENT_LIST_DIR.
In projects with just one CMakeLists.txt, these two variables
are equivalent. In multiproject builds, however, CMAKE_SOURCE_DIR
always points to the top level CMakeLists.txt while
CMAKE_CURRENT_LIST_DIR points to the CMakeLists.txt that is currently
being evaluated. CMAKE_CURRENT_LIST_DIR was added in cmake 2.8.3.
The generator constructs paths relative to the generated CMakeLists.txt
rather than to the build root. Therefore, CMAKE_CURRENT_LIST_DIR is the
more appropriate variable.
This change makes it possible to integrate a gyp-generated cmake
into a multi-project build without needing to switch the entire
build over to gyp. It also enables projects where the top level
cmake is handwritten (and possibly responsible for running gyp
to generate other cmake files). This makes usage in IDEs a bit
more convenient; at the very least, it stops CLion from complaining
that the source files don't live underneath the directory where
CMakeLists.txt lives. This also works with KDevelop, which has had
support for CMAKE_CURRENT_LIST_DIR since 4.1.
Base URL:
https://chromium.googlesource.com/external/gyp.git@master
Affected files (+6, -6 lines):
M pylib/gyp/generator/cmake.py
Index: pylib/gyp/generator/cmake.py
diff --git a/pylib/gyp/generator/cmake.py b/pylib/gyp/generator/cmake.py
index
eece6ea98ddd001072169d924f3b865b984baff6..be9d7a46c1d1a34356a94abe6e49116b9aca3ad4
100644
--- a/pylib/gyp/generator/cmake.py
+++ b/pylib/gyp/generator/cmake.py
@@ -55,7 +55,7 @@ generator_default_variables = {
'CONFIGURATION_NAME': '${configuration}',
}
-FULL_PATH_VARS = ('${CMAKE_SOURCE_DIR}', '${builddir}', '${obj}')
+FULL_PATH_VARS = ('${CMAKE_CURRENT_LIST_DIR}', '${builddir}', '${obj}')
generator_supports_multiple_toolsets = True
generator_wants_static_library_dependencies_adjusted = True
@@ -103,7 +103,7 @@ def NormjoinPathForceCMakeSource(base_path, rel_path):
if any([rel_path.startswith(var) for var in FULL_PATH_VARS]):
return rel_path
# TODO: do we need to check base_path for absolute variables as well?
- return os.path.join('${CMAKE_SOURCE_DIR}',
+ return os.path.join('${CMAKE_CURRENT_LIST_DIR}',
os.path.normpath(os.path.join(base_path, rel_path)))
@@ -293,7 +293,7 @@ def WriteActions(target_name, actions, extra_sources,
extra_deps,
WriteVariable(output, inputs_name)
output.write('\n')
- output.write(' WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/')
+ output.write(' WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/')
output.write(path_to_gyp)
output.write('\n')
@@ -398,9 +398,9 @@ def WriteRules(target_name, rules, extra_sources,
extra_deps,
output.write(NormjoinPath(path_to_gyp, rule_source))
output.write('\n')
- # CMAKE_SOURCE_DIR is where the CMakeLists.txt lives.
+ # CMAKE_CURRENT_LIST_DIR is where the CMakeLists.txt lives.
# The cwd is the current build directory.
- output.write(' WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/')
+ output.write(' WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/')
output.write(path_to_gyp)
output.write('\n')
@@ -522,7 +522,7 @@ def WriteCopies(target_name, copies, extra_deps,
path_to_gyp, output):
WriteVariable(output, copy.inputs_name, ' ')
output.write('\n')
- output.write('WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/')
+ output.write('WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/')
output.write(path_to_gyp)
output.write('\n')