From 98a187a8d49feecc05c8eb43caeb16a7230d75a3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Sun, 19 Feb 2006 13:10:25 -0500 Subject: [PATCH] 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. --- Source/cmLocalGenerator.cxx | 49 +++++++++---------- .../GeneratedHeader/CMakeLists.txt | 5 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a72faf9e2..d7cbd5b6b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1141,9 +1141,29 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang) //---------------------------------------------------------------------------- void cmLocalGenerator::GetIncludeDirectories(std::vector& 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 // automatically. Preserve compatibility. - bool includeSourceDir = false; const char* versionValue = m_Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); int major = 0; @@ -1156,11 +1176,13 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs) { 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 = m_Makefile->GetDefinition("VTK_SOURCE_DIR"); if(vtkSourceDir) { - // Special hack for VTK 4.0 - 4.4. const char* vtk_major = m_Makefile->GetDefinition("VTK_MAJOR_VERSION"); const char* vtk_minor = m_Makefile->GetDefinition("VTK_MINOR_VERSION"); vtk_major = vtk_major? vtk_major : "4"; @@ -1174,29 +1196,6 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& 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 emitted; diff --git a/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt b/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt index 0ab333b69..16d0ca48c 100644 --- a/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt +++ b/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt @@ -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 COMMAND ${CMAKE_COMMAND} ARGS -E @@ -5,6 +9,5 @@ ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.h ${CMAKE_CURRENT_BINARY_DIR}/generated.h ) -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR}) ADD_LIBRARY(GeneratedHeader main.cpp)