diff options
author | Brad King <brad.king@kitware.com> | 2006-02-18 16:51:23 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2006-02-18 16:51:23 (GMT) |
commit | 9ba02838701e2513414f258dec9d63566ee9b481 (patch) | |
tree | 5b268384b83211c28c03c46f68a2598396c3f4ba /Source/cmLocalGenerator.cxx | |
parent | fc70e3512ad2785daad4629f62309d12f1a3a32b (diff) | |
download | CMake-9ba02838701e2513414f258dec9d63566ee9b481.zip CMake-9ba02838701e2513414f258dec9d63566ee9b481.tar.gz CMake-9ba02838701e2513414f258dec9d63566ee9b481.tar.bz2 |
ENH: If CMAKE_NO_AUTOMATIC_INCLUDE_DIRECTORIES is not set try to approximate in-source build include file behavior in an out-of-source build by adding the build tree directory corresponding to a source tree directory at the beginning of the include path. Also fixed VS6 and VS7 generators to use cmLocalGenerator's computation of include paths. The VS6 generator will now short-path the include directories if the total length is too long in order to try to avoid its truncation limit.
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 42738f9..46fc4e9 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1129,22 +1129,20 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang) //---------------------------------------------------------------------------- void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs) { - // Output Include paths - std::set<cmStdString> implicitIncludes; - // CMake versions below 2.0 would add the source tree to the -I path // automatically. Preserve compatibility. bool includeSourceDir = false; const char* versionValue = m_Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); - if(versionValue) + int major = 0; + int minor = 0; + if(versionValue && sscanf(versionValue, "%d.%d", &major, &minor) != 2) { - int major = 0; - int minor = 0; - if(sscanf(versionValue, "%d.%d", &major, &minor) == 2 && major < 2) - { - includeSourceDir = true; - } + versionValue = 0; + } + if(versionValue && major < 2) + { + includeSourceDir = true; } const char* vtkSourceDir = m_Makefile->GetDefinition("VTK_SOURCE_DIR"); @@ -1164,23 +1162,59 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs) } } + // If this is not an in-source build then include the binary + // directory at the beginning of the include path to approximate + // include file behavior for an in-source build. This does not + // account for the case of a source file in a subdirectory of the + // current source directory but we cannot fix this because not all + // native build tools support per-source-file include paths. Allow + // the behavior to be disabled by the project. + bool includeBinaryDir = + !cmSystemTools::ComparePath(m_Makefile->GetStartDirectory(), + m_Makefile->GetStartOutputDirectory()); + if(m_Makefile->IsOn("CMAKE_NO_AUTOMATIC_INCLUDE_DIRECTORIES")) + { + includeSourceDir = false; + includeBinaryDir = false; + } + + // CMake versions 2.2 and earlier did not add the binary directory + // automatically. + if(versionValue && ((major < 2) || major == 2 && minor < 3)) + { + includeBinaryDir = false; + } + + // Do not repeat an include path. + std::set<cmStdString> emitted; + + // Store the automatic include paths. + if(includeBinaryDir) + { + dirs.push_back(m_Makefile->GetStartOutputDirectory()); + emitted.insert(m_Makefile->GetStartOutputDirectory()); + } if(includeSourceDir) { - dirs.push_back(m_Makefile->GetStartDirectory()); + if(emitted.find(m_Makefile->GetStartDirectory()) == emitted.end()) + { + dirs.push_back(m_Makefile->GetStartDirectory()); + emitted.insert(m_Makefile->GetStartDirectory()); + } } // Do not explicitly add the standard include path "/usr/include". // This can cause problems with certain standard library // implementations because the wrong headers may be found first. - implicitIncludes.insert("/usr/include"); - if(m_Makefile->GetDefinition("CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES")) + emitted.insert("/usr/include"); + if(const char* implicitIncludes = + m_Makefile->GetDefinition("CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES")) { - std::string arg = m_Makefile->GetDefinition("CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES"); std::vector<std::string> implicitIncludeVec; - cmSystemTools::ExpandListArgument(arg, implicitIncludeVec); - for(unsigned int k =0; k < implicitIncludeVec.size(); k++) + cmSystemTools::ExpandListArgument(implicitIncludes, implicitIncludeVec); + for(unsigned int k = 0; k < implicitIncludeVec.size(); ++k) { - implicitIncludes.insert(implicitIncludeVec[k]); + emitted.insert(implicitIncludeVec[k]); } } @@ -1189,9 +1223,10 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs) for(std::vector<std::string>::iterator i = includes.begin(); i != includes.end(); ++i) { - if(implicitIncludes.find(*i) == implicitIncludes.end()) + if(emitted.find(*i) == emitted.end()) { dirs.push_back(*i); + emitted.insert(*i); } } } |