cmake: Fix dependency loops in custom targets (fixes #6632)
This commit is contained in:
parent
73ddc01477
commit
4ec6918cd5
|
@ -26,6 +26,7 @@ from ..mesonlib import MachineChoice, version_compare
|
||||||
from ..compilers.compilers import lang_suffixes, header_suffixes, obj_suffixes, lib_suffixes, is_header
|
from ..compilers.compilers import lang_suffixes, header_suffixes, obj_suffixes, lib_suffixes, is_header
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
from pathlib import Path
|
||||||
import typing as T
|
import typing as T
|
||||||
import os, re
|
import os, re
|
||||||
|
|
||||||
|
@ -659,23 +660,35 @@ class ConverterCustomTarget:
|
||||||
self.outputs = [self.name + '.h']
|
self.outputs = [self.name + '.h']
|
||||||
|
|
||||||
# Check dependencies and input files
|
# Check dependencies and input files
|
||||||
|
root = Path(root_src_dir)
|
||||||
for i in self.depends_raw:
|
for i in self.depends_raw:
|
||||||
if not i:
|
if not i:
|
||||||
continue
|
continue
|
||||||
|
raw = Path(i)
|
||||||
art = output_target_map.artifact(i)
|
art = output_target_map.artifact(i)
|
||||||
tgt = output_target_map.target(i)
|
tgt = output_target_map.target(i)
|
||||||
gen = output_target_map.generated(i)
|
gen = output_target_map.generated(i)
|
||||||
|
|
||||||
if art:
|
rel_to_root = None
|
||||||
|
try:
|
||||||
|
rel_to_root = raw.relative_to(root)
|
||||||
|
except ValueError:
|
||||||
|
rel_to_root = None
|
||||||
|
|
||||||
|
# First check for existing files. Only then check for existing
|
||||||
|
# targets, etc. This reduces the chance of misdetecting input files
|
||||||
|
# as outputs from other targets.
|
||||||
|
# See https://github.com/mesonbuild/meson/issues/6632
|
||||||
|
if not raw.is_absolute() and (root / raw).exists():
|
||||||
|
self.inputs += [raw.as_posix()]
|
||||||
|
elif raw.is_absolute() and raw.exists() and rel_to_root is not None:
|
||||||
|
self.inputs += [rel_to_root.as_posix()]
|
||||||
|
elif art:
|
||||||
self.depends += [art]
|
self.depends += [art]
|
||||||
elif tgt:
|
elif tgt:
|
||||||
self.depends += [tgt]
|
self.depends += [tgt]
|
||||||
elif gen:
|
elif gen:
|
||||||
self.inputs += [gen.get_ref(i)]
|
self.inputs += [gen.get_ref(i)]
|
||||||
elif not os.path.isabs(i) and os.path.exists(os.path.join(root_src_dir, i)):
|
|
||||||
self.inputs += [i]
|
|
||||||
elif os.path.isabs(i) and os.path.exists(i) and os.path.commonpath([i, root_src_dir]) == root_src_dir:
|
|
||||||
self.inputs += [os.path.relpath(i, root_src_dir)]
|
|
||||||
|
|
||||||
def process_inter_target_dependencies(self):
|
def process_inter_target_dependencies(self):
|
||||||
# Move the dependencies from all transfer_dependencies_from to the target
|
# Move the dependencies from all transfer_dependencies_from to the target
|
||||||
|
|
|
@ -89,7 +89,27 @@ add_custom_command(
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp"
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(cmModLib SHARED cmMod.cpp genTest.cpp cpyBase.cpp cpyBase.hpp cpyNext.cpp cpyNext.hpp)
|
# cpyTest (copy file without renaming)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest.hpp"
|
||||||
|
COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest.hpp" "${CMAKE_CURRENT_BINARY_DIR}/cpyTest.hpp"
|
||||||
|
DEPENDS "cpyTest/cpyTest.hpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest2.hpp"
|
||||||
|
COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest2.hpp" "${CMAKE_CURRENT_BINARY_DIR}/cpyTest2.hpp"
|
||||||
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest2.hpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest3.hpp"
|
||||||
|
COMMAND mycpy cpyTest3.hpp "${CMAKE_CURRENT_BINARY_DIR}/cpyTest3.hpp"
|
||||||
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest3.hpp"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(cmModLib SHARED cmMod.cpp genTest.cpp cpyBase.cpp cpyBase.hpp cpyNext.cpp cpyNext.hpp cpyTest.cpp cpyTest.hpp cpyTest2.hpp cpyTest3.hpp)
|
||||||
include(GenerateExportHeader)
|
include(GenerateExportHeader)
|
||||||
generate_export_header(cmModLib)
|
generate_export_header(cmModLib)
|
||||||
|
|
||||||
|
@ -99,7 +119,7 @@ set(ARGS_TEST ${ARGS_TEST} arg2)
|
||||||
add_executable(macro_name macro_name.cpp)
|
add_executable(macro_name macro_name.cpp)
|
||||||
add_executable(args_test args_test.cpp)
|
add_executable(args_test args_test.cpp)
|
||||||
add_custom_target(args_test_cmd
|
add_custom_target(args_test_cmd
|
||||||
COMMAND args_test ARGS ${ARGS_TEST}
|
COMMAND args_test ${ARGS_TEST}
|
||||||
)
|
)
|
||||||
add_custom_target(macro_name_cmd COMMAND macro_name)
|
add_custom_target(macro_name_cmd COMMAND macro_name)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "genTest.hpp"
|
#include "genTest.hpp"
|
||||||
#include "cpyBase.hpp"
|
#include "cpyBase.hpp"
|
||||||
#include "cpyNext.hpp"
|
#include "cpyNext.hpp"
|
||||||
|
#include "cpyTest.hpp"
|
||||||
#include "cmModLib.hpp"
|
#include "cmModLib.hpp"
|
||||||
|
|
||||||
#ifndef FOO
|
#ifndef FOO
|
||||||
|
@ -19,5 +20,5 @@ string cmModClass::getStr() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
string cmModClass::getOther() const {
|
string cmModClass::getOther() const {
|
||||||
return "Srings:\n - " + getStrCpy() + "\n - " + getStrNext();
|
return "Srings:\n - " + getStrCpy() + "\n - " + getStrNext() + "\n - " + getStrCpyTest();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "cpyTest.hpp"
|
||||||
|
#include "cpyTest2.hpp"
|
||||||
|
#include "cpyTest3.hpp"
|
||||||
|
|
||||||
|
std::string getStrCpyTest() {
|
||||||
|
return CPY_TEST_STR_2 CPY_TEST_STR_3;
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::string getStrCpyTest();
|
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define CPY_TEST_STR_2 "Hello "
|
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define CPY_TEST_STR_3 "CopyFile"
|
Loading…
Reference in New Issue