mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Genex: LINK_LANGUAGE respects LINKER_LANGUAGE property
If target property LINKER_LANGUAGE is set, LINK_LANGUAGE generator expression evaluation must be always successful. This fix can be helpful to elaborate a solution for issue #21818.
This commit is contained in:
@@ -2648,8 +2648,12 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
|
||||
LinkClosure linkClosure;
|
||||
linkClosure.LinkerLanguage = this->LinkerLanguage;
|
||||
|
||||
bool hasHardCodedLinkerLanguage = this->Target->GetProperty("HAS_CXX") ||
|
||||
!this->Target->GetSafeProperty("LINKER_LANGUAGE").empty();
|
||||
|
||||
// Get languages built in this target.
|
||||
secondPass = this->ComputeLinkClosure(config, linkClosure, false);
|
||||
secondPass = this->ComputeLinkClosure(config, linkClosure, false) &&
|
||||
!hasHardCodedLinkerLanguage;
|
||||
this->LinkerLanguage = linkClosure.LinkerLanguage;
|
||||
if (!secondPass) {
|
||||
lc = std::move(linkClosure);
|
||||
|
@@ -34,6 +34,7 @@ if (RunCMake_GENERATOR MATCHES "Makefiles|Ninja|Visual Studio|Xcode|Watcom WMake
|
||||
run_cmake_target(genex CXX_interface2 LinkLibraries_CXX_interface2 --config Release)
|
||||
run_cmake_target(genex C_static LinkLibraries_C_static --config Release)
|
||||
run_cmake_target(genex CXX_static LinkLibraries_CXX_static --config Release)
|
||||
run_cmake_target(genex C_static_CXX LinkLibraries_C_static_CXX --config Release)
|
||||
|
||||
unset(RunCMake_TEST_OPTIONS)
|
||||
unset(RunCMake_TEST_OUTPUT_MERGE)
|
||||
|
@@ -1,7 +1,18 @@
|
||||
|
||||
#if defined(_WIN32)
|
||||
__declspec(dllexport)
|
||||
#if !defined(BUILD_STATIC) && defined(_WIN32)
|
||||
# define EXPORT_SYMBOL __declspec(dllexport)
|
||||
#else
|
||||
# define EXPORT_SYMBOL
|
||||
#endif
|
||||
void func_cxx()
|
||||
|
||||
EXPORT_SYMBOL
|
||||
void func_cxx()
|
||||
{
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
EXPORT_SYMBOL
|
||||
void func_c_cxx()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@ enable_language(CXX)
|
||||
add_library(shared_C SHARED func.c)
|
||||
add_library(shared_CXX SHARED func.cxx)
|
||||
|
||||
add_library(static_cxx STATIC func.cxx)
|
||||
target_compile_definitions(static_cxx PRIVATE BUILD_STATIC)
|
||||
|
||||
add_library(static1_C STATIC empty.c)
|
||||
target_link_libraries (static1_C INTERFACE $<$<LINK_LANGUAGE:C>:shared_C>)
|
||||
@@ -70,3 +72,10 @@ add_executable(LinkLibraries_C_static main.c)
|
||||
target_link_libraries (LinkLibraries_C_static PRIVATE static3)
|
||||
add_executable(LinkLibraries_CXX_static main.cxx)
|
||||
target_link_libraries (LinkLibraries_CXX_static PRIVATE static3)
|
||||
|
||||
# $<LINK_LANGUAGE:> change, by default, link language from C to CXX
|
||||
# but because LINKER_LANGUAGE property is set, keep C as link language
|
||||
add_executable(LinkLibraries_C_static_CXX main.c)
|
||||
target_compile_definitions (LinkLibraries_C_static_CXX PRIVATE C_USE_CXX)
|
||||
target_link_libraries (LinkLibraries_C_static_CXX PRIVATE $<$<LINK_LANGUAGE:C>:static_cxx>)
|
||||
set_property(TARGET LinkLibraries_C_static_CXX PROPERTY LINKER_LANGUAGE C)
|
||||
|
@@ -1,12 +1,20 @@
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(C_USE_CXX)
|
||||
void func_c_cxx();
|
||||
#else
|
||||
# if defined(_WIN32)
|
||||
__declspec(dllimport)
|
||||
#endif
|
||||
# endif
|
||||
void func_c();
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if defined(C_USE_CXX)
|
||||
func_c_cxx();
|
||||
#else
|
||||
func_c();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user