From c5eb21b6d1f4187778ad49545761a818e1126541 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 5 Feb 2016 08:55:15 -0500 Subject: [PATCH] Fix dependency scanning configuration in subdirectories Refactoring in commit v3.5.0-rc1~347^2~2 (Set the current dirs on the snapshot before creating the cmMakefile) accidentally changed the source and binary directories configured in `cmake -E cmake_depends` for use during dependency scanning. This can cause the wrong directory information to be loaded. It also breaks Fortran module dependency scanning for modules provided by targets in subdirectories that do not have Fortran_MODULE_DIRECTORY set. Fix the dependency scanning directory configuration and add a test to cover the Fortran module case in which the breakage was observed. Reported-by: Kelly Thompson --- Source/cmcmd.cxx | 6 ++---- Tests/Fortran/CMakeLists.txt | 1 + Tests/Fortran/Executable/CMakeLists.txt | 2 +- Tests/Fortran/Executable/main.f90 | 1 + Tests/Fortran/Subdir/CMakeLists.txt | 2 ++ Tests/Fortran/Subdir/subdir.f90 | 2 ++ 6 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 Tests/Fortran/Subdir/CMakeLists.txt create mode 100644 Tests/Fortran/Subdir/subdir.f90 diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 1dc304c3a..e9d77b250 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -813,10 +813,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) { cm.SetGlobalGenerator(ggd); cmState::Snapshot snapshot = cm.GetCurrentSnapshot(); - snapshot.GetDirectory().SetCurrentBinary - (cmSystemTools::GetCurrentWorkingDirectory()); - snapshot.GetDirectory().SetCurrentSource - (cmSystemTools::GetCurrentWorkingDirectory()); + snapshot.GetDirectory().SetCurrentBinary(startOutDir); + snapshot.GetDirectory().SetCurrentSource(startDir); cmsys::auto_ptr mf(new cmMakefile(ggd, snapshot)); cmsys::auto_ptr lgd( ggd->CreateLocalGenerator(mf.get())); diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt index 753ce2796..ecf38a605 100644 --- a/Tests/Fortran/CMakeLists.txt +++ b/Tests/Fortran/CMakeLists.txt @@ -223,5 +223,6 @@ if(TEST_MODULE_DEPENDS) endif() add_subdirectory(Library) + add_subdirectory(Subdir) add_subdirectory(Executable) endif() diff --git a/Tests/Fortran/Executable/CMakeLists.txt b/Tests/Fortran/Executable/CMakeLists.txt index 55f21ad46..de08d8605 100644 --- a/Tests/Fortran/Executable/CMakeLists.txt +++ b/Tests/Fortran/Executable/CMakeLists.txt @@ -3,6 +3,6 @@ include_directories(${External_BINARY_DIR}) link_directories(${External_BINARY_DIR}) add_executable(subdir_exe2 main.f90) -target_link_libraries(subdir_exe2 subdir_mods) +target_link_libraries(subdir_exe2 subdir_mods subdir_mods2) add_dependencies(subdir_exe2 ExternalTarget) target_link_libraries(subdir_exe2 myext) diff --git a/Tests/Fortran/Executable/main.f90 b/Tests/Fortran/Executable/main.f90 index f21156cda..640259c12 100644 --- a/Tests/Fortran/Executable/main.f90 +++ b/Tests/Fortran/Executable/main.f90 @@ -1,6 +1,7 @@ PROGRAM MAINF90 USE libraryModuleA USE libraryModuleB + USE subdirModuleA USE externalMod CALL printExtModGreeting END PROGRAM MAINF90 diff --git a/Tests/Fortran/Subdir/CMakeLists.txt b/Tests/Fortran/Subdir/CMakeLists.txt new file mode 100644 index 000000000..52683e587 --- /dev/null +++ b/Tests/Fortran/Subdir/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(subdir_mods2 subdir.f90) +target_include_directories(subdir_mods2 INTERFACE ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Tests/Fortran/Subdir/subdir.f90 b/Tests/Fortran/Subdir/subdir.f90 new file mode 100644 index 000000000..68955f6b5 --- /dev/null +++ b/Tests/Fortran/Subdir/subdir.f90 @@ -0,0 +1,2 @@ +MODULE subdirModuleA +END MODULE