diff options
author | Brad King <brad.king@kitware.com> | 2019-02-05 12:30:55 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-02-05 12:36:36 (GMT) |
commit | c6d679f0d904b19b3be411b399b5904a5da7ea78 (patch) | |
tree | 7b7f555f3d93bec170dbc70e6cb21159bfc6e438 | |
parent | c03072f2f7a08c6ddf0cec58dfc8ea2b83f4c1a9 (diff) | |
parent | d3d2c3cd497e09281a8f237b5a4cd35d8cd298f0 (diff) | |
download | CMake-c6d679f0d904b19b3be411b399b5904a5da7ea78.zip CMake-c6d679f0d904b19b3be411b399b5904a5da7ea78.tar.gz CMake-c6d679f0d904b19b3be411b399b5904a5da7ea78.tar.bz2 |
Merge topic 'vs-fortran-target-check'
d3d2c3cd49 VS: Fix Fortran target type selection when linking C++ targets
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2913
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.cxx | 31 | ||||
-rw-r--r-- | Tests/Fortran/CMakeLists.txt | 5 |
2 files changed, 17 insertions, 19 deletions
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 77be592..1922906 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -813,7 +813,6 @@ bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly( cmGeneratorTarget const* gt) { // check to see if this is a fortran build - std::set<std::string> languages; { // Issue diagnostic if the source files depend on the config. std::vector<cmSourceFile*> sources; @@ -821,27 +820,21 @@ bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly( return false; } } + // If there's only one source language, Fortran has to be used // in order for the sources to compile. - // Note: Via linker propagation, LINKER_LANGUAGE could become CXX in - // this situation and mismatch from the actual language of the linker. + std::set<std::string> languages; gt->GetLanguages(languages, ""); - if (languages.size() == 1) { - if (*languages.begin() == "Fortran") { - return true; - } - } - - // In the case of mixed object files or sources mixed with objects, - // decide the language based on the value of LINKER_LANGUAGE. - // This will not make it possible to mix source files of different - // languages, but object libraries will be linked together in the - // same fashion as other generators do. - if (gt->GetLinkerLanguage("") == "Fortran") { - return true; - } - - return false; + // Consider an explicit linker language property, but *not* the + // computed linker language that may depend on linked targets. + // This allows the project to control the language choice in + // a target with none of its own sources, e.g. when also using + // object libraries. + const char* linkLang = gt->GetProperty("LINKER_LANGUAGE"); + if (linkLang && *linkLang) { + languages.insert(linkLang); + } + return languages.size() == 1 && *languages.begin() == "Fortran"; } bool cmGlobalVisualStudioGenerator::TargetCompare::operator()( diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt index 52623d0..7023615 100644 --- a/Tests/Fortran/CMakeLists.txt +++ b/Tests/Fortran/CMakeLists.txt @@ -99,6 +99,11 @@ function(test_fortran_c_interface_module) target_link_libraries(myc myfort) set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS}) + add_library(myfort_obj OBJECT mysub.f) + add_library(myc_use_obj myc.c $<TARGET_OBJECTS:myfort_obj>) + add_executable(mainc_use_obj mainc.c) + target_link_libraries(mainc_use_obj myc_use_obj) + add_library(mycxx mycxx.cxx) target_link_libraries(mycxx myc) |