Tests: Add FileAPI case for cross-directory target_* commands

The backtraces for some of the commands incorrectly come from the
target's directory instead of the caller's directory.  Expect the
incorrect backtraces in test results for now.

Increase the minimum required version of CMake in the test case
to enable policy CMP0079 to support cross-directory calls.

Issue: #23873
This commit is contained in:
Brad King
2022-08-22 11:40:07 -04:00
parent ef6a4240ba
commit 0d64c3abd1
22 changed files with 247 additions and 33 deletions

View File

@@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.13)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -664,6 +664,7 @@ def gen_check_directories(c, g):
read_codemodel_json_data("directories/dir_dir.json"),
read_codemodel_json_data("directories/external.json"),
read_codemodel_json_data("directories/fileset.json"),
read_codemodel_json_data("directories/subdir.json"),
]
if matches(g["name"], "^Visual Studio "):
@@ -722,6 +723,7 @@ def gen_check_targets(c, g, inSource):
read_codemodel_json_data("targets/c_shared_exe.json"),
read_codemodel_json_data("targets/c_static_lib.json"),
read_codemodel_json_data("targets/c_static_exe.json"),
read_codemodel_json_data("targets/c_subdir.json"),
read_codemodel_json_data("targets/all_build_cxx.json"),
read_codemodel_json_data("targets/zero_check_cxx.json"),

View File

@@ -10,7 +10,7 @@
"^cxx_alias_exe::@53632cba2752272bb008$"
],
"projectName": "Alias",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": null,
"installers": []
}

View File

@@ -10,7 +10,7 @@
"^custom_tgt::@c11385ffed57b860da63$"
],
"projectName": "Custom",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": null,
"installers": []
}

View File

@@ -16,7 +16,7 @@
"^cxx_static_lib::@a56b12a3f5c0529fb296$"
],
"projectName": "Cxx",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": true,
"installers": [
{

View File

@@ -7,7 +7,7 @@
],
"targetIds": null,
"projectName": "codemodel-v2",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": null,
"installers": []
}

View File

@@ -5,7 +5,7 @@
"childSources": null,
"targetIds": null,
"projectName": "codemodel-v2",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": null,
"installers": []
}

View File

@@ -9,7 +9,7 @@
"^generated_exe::@[0-9a-f]+$"
],
"projectName": "External",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": true,
"installers": [
{

View File

@@ -8,7 +8,7 @@
"^c_headers_2::@6b8db101d64c125f29fe$"
],
"projectName": "codemodel-v2",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": true,
"installers": [
{

View File

@@ -13,7 +13,7 @@
"^link_imported_static_exe::@ba7eb709d0b48779c6c8$"
],
"projectName": "Imported",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": true,
"installers": [
{

View File

@@ -9,7 +9,7 @@
"^iface_srcs::@25b7fa8ea00134654b85$"
],
"projectName": "Interface",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": null,
"installers": []
}

View File

@@ -0,0 +1,11 @@
{
"source": "^subdir$",
"build": "^subdir$",
"parentSource": "^\\.$",
"childSources": null,
"targetIds": null,
"projectName": "codemodel-v2",
"minimumCMakeVersion": "3.13",
"hasInstallRule": null,
"installers": []
}

View File

@@ -11,7 +11,8 @@
"^object$",
"^.*/Tests/RunCMake/FileAPIExternalSource$",
"^dir$",
"^fileset$"
"^fileset$",
"^subdir$"
],
"targetIds": [
"^ALL_BUILD::@6890427a1f51a3e7e1df$",
@@ -22,10 +23,11 @@
"^c_shared_lib::@6890427a1f51a3e7e1df$",
"^c_static_exe::@6890427a1f51a3e7e1df$",
"^c_static_lib::@6890427a1f51a3e7e1df$",
"^c_subdir::@6890427a1f51a3e7e1df$",
"^interface_exe::@6890427a1f51a3e7e1df$"
],
"projectName": "codemodel-v2",
"minimumCMakeVersion": "3.12",
"minimumCMakeVersion": "3.13",
"hasInstallRule": true,
"installers": [
{
@@ -48,7 +50,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 39,
"line": 42,
"command": "install",
"hasParent": true
},
@@ -93,7 +95,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 42,
"line": 45,
"command": "install",
"hasParent": true
},
@@ -141,7 +143,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 42,
"line": 45,
"command": "install",
"hasParent": true
},
@@ -186,7 +188,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 42,
"line": 45,
"command": "install",
"hasParent": true
},
@@ -230,7 +232,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 42,
"line": 45,
"command": "install",
"hasParent": true
},
@@ -274,7 +276,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 47,
"line": 50,
"command": "install",
"hasParent": true
},
@@ -321,7 +323,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 49,
"line": 52,
"command": "install",
"hasParent": true
},
@@ -366,7 +368,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 50,
"line": 53,
"command": "install",
"hasParent": true
},
@@ -415,7 +417,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 51,
"line": 54,
"command": "install",
"hasParent": true
},
@@ -467,7 +469,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 52,
"line": 55,
"command": "install",
"hasParent": true
},
@@ -516,7 +518,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 53,
"line": 56,
"command": "install",
"hasParent": true
},
@@ -558,7 +560,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 54,
"line": 57,
"command": "install",
"hasParent": true
},
@@ -600,7 +602,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 55,
"line": 58,
"command": "install",
"hasParent": true
},

View File

@@ -14,7 +14,8 @@
"^\\.$",
"^dir$",
"^dir/dir$",
"^fileset$"
"^fileset$",
"^subdir$"
],
"targetIds": [
"^ALL_BUILD::@6890427a1f51a3e7e1df$",
@@ -26,6 +27,7 @@
"^c_shared_exe::@6890427a1f51a3e7e1df$",
"^c_static_lib::@6890427a1f51a3e7e1df$",
"^c_static_exe::@6890427a1f51a3e7e1df$",
"^c_subdir::@6890427a1f51a3e7e1df$",
"^c_headers_1::@6b8db101d64c125f29fe$",
"^c_headers_2::@6b8db101d64c125f29fe$"
]

View File

@@ -95,6 +95,10 @@
"id": "^c_static_lib::@6890427a1f51a3e7e1df$",
"backtrace": null
},
{
"id": "^c_subdir::@6890427a1f51a3e7e1df$",
"backtrace": null
},
{
"id": "^c_static_exe::@6890427a1f51a3e7e1df$",
"backtrace": null

View File

@@ -115,7 +115,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 42,
"line": 45,
"command": "install",
"hasParent": true
},
@@ -145,7 +145,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 42,
"line": 45,
"command": "install",
"hasParent": true
},
@@ -175,7 +175,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 47,
"line": 50,
"command": "install",
"hasParent": true
},

View File

@@ -0,0 +1,186 @@
{
"name": "c_subdir",
"id": "^c_subdir::@6890427a1f51a3e7e1df$",
"directorySource": "^\\.$",
"projectName": "codemodel-v2",
"type": "STATIC_LIBRARY",
"isGeneratorProvided": null,
"sources": [
{
"path": "^subdir/empty\\.c$",
"isGenerated": null,
"sourceGroupName": "Source Files",
"compileGroupLanguage": "C",
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 18,
"command": "add_subdirectory",
"hasParent": true
},
{
"file": "^codemodel-v2\\.cmake$",
"line": null,
"command": null,
"hasParent": true
},
{
"file": "^CMakeLists\\.txt$",
"line": 3,
"command": "include",
"hasParent": true
},
{
"file": "^CMakeLists\\.txt$",
"line": null,
"command": null,
"hasParent": false
}
]
}
],
"sourceGroups": [
{
"name": "Source Files",
"sourcePaths": [
"^subdir/empty\\.c$"
]
}
],
"compileGroups": [
{
"language": "C",
"sourcePaths": [
"^subdir/empty\\.c$"
],
"includes": [
{
"path": "^.*/Tests/RunCMake/FileAPI/subdir$",
"isSystem": null,
"backtrace": [
{
"file": "^subdir/CMakeLists\\.txt$",
"line": 2,
"command": "target_include_directories",
"hasParent": true
},
{
"file": "^subdir/CMakeLists\\.txt$",
"line": null,
"command": null,
"hasParent": false
}
]
}
],
"defines": [
{
"define": "SUBDIR",
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 18,
"command": "add_subdirectory",
"hasParent": true
},
{
"file": "^codemodel-v2\\.cmake$",
"line": null,
"command": null,
"hasParent": true
},
{
"file": "^CMakeLists\\.txt$",
"line": 3,
"command": "include",
"hasParent": true
},
{
"file": "^CMakeLists\\.txt$",
"line": null,
"command": null,
"hasParent": false
}
]
}
],
"compileCommandFragments": null
}
],
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 17,
"command": "add_library",
"hasParent": true
},
{
"file": "^codemodel-v2\\.cmake$",
"line": null,
"command": null,
"hasParent": true
},
{
"file": "^CMakeLists\\.txt$",
"line": 3,
"command": "include",
"hasParent": true
},
{
"file": "^CMakeLists\\.txt$",
"line": null,
"command": null,
"hasParent": false
}
],
"folder": null,
"nameOnDisk": "^(lib)?c_subdir\\.(a|lib)$",
"artifacts": [
{
"path": "^((Debug|Release|RelWithDebInfo|MinSizeRel)/)?(lib)?c_subdir\\.(a|lib)$",
"_dllExtra": false
}
],
"build": "^\\.$",
"source": "^\\.$",
"install": null,
"link": null,
"archive": {
"lto": null
},
"dependencies": [
{
"id": "^c_lib::@6890427a1f51a3e7e1df$",
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 18,
"command": "add_subdirectory",
"hasParent": true
},
{
"file": "^codemodel-v2\\.cmake$",
"line": null,
"command": null,
"hasParent": true
},
{
"file": "^CMakeLists\\.txt$",
"line": 3,
"command": "include",
"hasParent": true
},
{
"file": "^CMakeLists\\.txt$",
"line": null,
"command": null,
"hasParent": false
}
]
},
{
"id": "^ZERO_CHECK::@6890427a1f51a3e7e1df$",
"backtrace": null
}
]
}

View File

@@ -136,7 +136,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 39,
"line": 42,
"command": "install",
"hasParent": true
},

View File

@@ -91,7 +91,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 42,
"line": 45,
"command": "install",
"hasParent": true
},
@@ -121,7 +121,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 42,
"line": 45,
"command": "install",
"hasParent": true
},
@@ -151,7 +151,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
"line": 47,
"line": 50,
"command": "install",
"hasParent": true
},

View File

@@ -14,6 +14,9 @@ add_library(c_static_lib STATIC empty.c)
add_executable(c_static_exe empty.c)
target_link_libraries(c_static_exe PRIVATE c_static_lib)
add_library(c_subdir STATIC)
add_subdirectory(subdir)
add_subdirectory(cxx)
add_subdirectory(alias)
add_subdirectory(object)

View File

@@ -0,0 +1,4 @@
target_compile_definitions(c_subdir PRIVATE SUBDIR)
target_include_directories(c_subdir PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(c_subdir PRIVATE c_lib)
target_sources(c_subdir PRIVATE empty.c)

View File