ENH: Automatic include directories should not be done by default as was just implemented. Instead a project may now set CMAKE_INCLUDE_CURRENT_DIR to get this behavior. The current source and binary directories are added automatically to the beginning of the include path in every directory. This simulates in-source behavior for double-quote includes when there are generated sources and headers in the directory.
This commit is contained in:
parent
b6fd3b7bb1
commit
98a187a8d4
@ -1141,9 +1141,29 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs)
|
void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs)
|
||||||
{
|
{
|
||||||
|
// Need to decide whether to automatically include the source and
|
||||||
|
// binary directories at the beginning of the include path.
|
||||||
|
bool includeSourceDir = false;
|
||||||
|
bool includeBinaryDir = false;
|
||||||
|
|
||||||
|
// When automatic include directories are requested for an
|
||||||
|
// out-of-source build then include the source and binary
|
||||||
|
// directories 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.
|
||||||
|
bool inSource =
|
||||||
|
cmSystemTools::ComparePath(m_Makefile->GetStartDirectory(),
|
||||||
|
m_Makefile->GetStartOutputDirectory());
|
||||||
|
if(!inSource && m_Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
|
||||||
|
{
|
||||||
|
includeSourceDir = true;
|
||||||
|
includeBinaryDir = true;
|
||||||
|
}
|
||||||
|
|
||||||
// CMake versions below 2.0 would add the source tree to the -I path
|
// CMake versions below 2.0 would add the source tree to the -I path
|
||||||
// automatically. Preserve compatibility.
|
// automatically. Preserve compatibility.
|
||||||
bool includeSourceDir = false;
|
|
||||||
const char* versionValue =
|
const char* versionValue =
|
||||||
m_Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
|
m_Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
|
||||||
int major = 0;
|
int major = 0;
|
||||||
@ -1156,11 +1176,13 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs)
|
|||||||
{
|
{
|
||||||
includeSourceDir = true;
|
includeSourceDir = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
|
||||||
|
// not set the backwards compatibility level automatically.
|
||||||
const char* vtkSourceDir =
|
const char* vtkSourceDir =
|
||||||
m_Makefile->GetDefinition("VTK_SOURCE_DIR");
|
m_Makefile->GetDefinition("VTK_SOURCE_DIR");
|
||||||
if(vtkSourceDir)
|
if(vtkSourceDir)
|
||||||
{
|
{
|
||||||
// Special hack for VTK 4.0 - 4.4.
|
|
||||||
const char* vtk_major = m_Makefile->GetDefinition("VTK_MAJOR_VERSION");
|
const char* vtk_major = m_Makefile->GetDefinition("VTK_MAJOR_VERSION");
|
||||||
const char* vtk_minor = m_Makefile->GetDefinition("VTK_MINOR_VERSION");
|
const char* vtk_minor = m_Makefile->GetDefinition("VTK_MINOR_VERSION");
|
||||||
vtk_major = vtk_major? vtk_major : "4";
|
vtk_major = vtk_major? vtk_major : "4";
|
||||||
@ -1174,29 +1196,6 @@ 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.
|
// Do not repeat an include path.
|
||||||
std::set<cmStdString> emitted;
|
std::set<cmStdString> emitted;
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# Simulate in-source build include-file behavior for out-of-source
|
||||||
|
# builds.
|
||||||
|
SET(CMAKE_INCLUDE_CURRENT_DIR 1)
|
||||||
|
|
||||||
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.h
|
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.h
|
||||||
COMMAND
|
COMMAND
|
||||||
${CMAKE_COMMAND} ARGS -E
|
${CMAKE_COMMAND} ARGS -E
|
||||||
@ -5,6 +9,5 @@ ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.h
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/generated.h
|
||||||
)
|
)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
ADD_LIBRARY(GeneratedHeader main.cpp)
|
ADD_LIBRARY(GeneratedHeader main.cpp)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user