Add -DCLING_INCLUDE_PATHS to CMake.

This allows a user to prepend to CLING_INCLUDE_PATHS any additional include paths
they want to add on startup.

Refactor common path splitting code into Utils/Paths

Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
This commit is contained in:
Frederich Munch 2016-08-12 15:54:47 -04:00 committed by sftnight
parent b8b4becaf6
commit ea25014f1f
7 changed files with 125 additions and 44 deletions

View File

@ -356,14 +356,25 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
)
endif()
add_definitions( -D_GNU_SOURCE
-DCLING_VERSION=${CLING_VERSION}
-DCLING_INCLUDE_PATHS="${CMAKE_INSTALL_PREFIX}/include:${CMAKE_CURRENT_SOURCE_DIR}/include:${CMAKE_CURRENT_SOURCE_DIR}/../clang/include:${CMAKE_CURRENT_SOURCE_DIR}/../../include" )
add_definitions( -D_GNU_SOURCE -DCLING_VERSION=${CLING_VERSION})
option(CLING_INCLUDE_TESTS
"Generate build targets for the Cling unit tests."
${LLVM_INCLUDE_TESTS})
#Allow user to prepend to list via cmake -DCLING_INCLUDE_PATHS=
set(cling_include_deflt "\
${CMAKE_INSTALL_PREFIX}/include:${CMAKE_CURRENT_SOURCE_DIR}/include:\
${CMAKE_CURRENT_SOURCE_DIR}/../clang/include:\
${CMAKE_CURRENT_SOURCE_DIR}/../../include"
)
if(NOT CLING_INCLUDE_PATHS)
set(CLING_INCLUDE_PATHS "${cling_include_deflt}")
else()
set(CLING_INCLUDE_PATHS "${CLING_INCLUDE_PATHS}:${cling_include_deflt}")
endif()
# All targets below may depend on all tablegen'd files.
get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS)
list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS})

View File

@ -0,0 +1,37 @@
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author:
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
#ifndef CLING_UTILS_PATHS_H
#define CLING_UTILS_PATHS_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
namespace cling {
namespace utils {
///\brief Collect the constituant paths from a PATH string.
/// /bin:/usr/bin:/usr/local/bin -> {/bin, /usr/bin, /usr/local/bin}
///
/// All paths returned existed at the time of the call
/// \param [in] PathStr - The PATH string to be split
/// \param [out] Paths - All the paths in the string that exist
/// \param [in] EarlyOut - If any path doesn't exist stop and return false
/// \param [in] Delim - The delimeter to use
///
/// \return true if all paths existed, otherwise false
///
bool SplitPaths(llvm::StringRef PathStr,
llvm::SmallVectorImpl<llvm::StringRef>& Paths,
bool EarlyOut = false,
llvm::StringRef Delim = llvm::StringRef(":"));
}
}
#endif // CLING_UTILS_PATHS_H

View File

@ -8,6 +8,7 @@
//------------------------------------------------------------------------------
#include "cling/Interpreter/CIFactory.h"
#include "cling/Utils/Paths.h"
#include "ClingUtils.h"
#include "DeclCollector.h"
@ -588,27 +589,14 @@ namespace {
}
static bool AddCxxPaths(llvm::StringRef PathStr, AdditionalArgList& Args) {
bool Success = true;
llvm::SmallVector<llvm::StringRef, 6> Paths;
for (std::pair<llvm::StringRef, llvm::StringRef> Split
= PathStr.split(':');
!Split.second.empty(); Split = PathStr.split(':')) {
if (!llvm::sys::fs::is_directory(Split.first)) {
Success = false;
break;
}
Paths.push_back(Split.first);
PathStr = Split.second;
}
// Add remaining part
if (Success && llvm::sys::fs::is_directory(PathStr)) {
llvm::SmallVector<llvm::StringRef, 6> Paths;
if (!cling::utils::SplitPaths(PathStr, Paths, true))
return false;
for (llvm::StringRef Path : Paths)
Args.addArgument("-I", Path.str());
Args.addArgument("-I", PathStr.str());
return true;
}
return false;
}
#endif

View File

@ -253,12 +253,14 @@ if (UNIX)
#define CLING_CXX_INCL \"${CLING_CXX_HEADERS}\"
#define CLING_CXX_PATH \"${CLING_CXX_PATH} ${CMAKE_CXX_FLAGS_NO_I} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}\"
#define CLING_CXX_RLTV \"${CLING_CXX_RLTV} ${CMAKE_CXX_FLAGS_NO_I} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}\"
#define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\"
")
else()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in
"
#define CLING_CXX_INCL \"${CLING_CXX_HEADERS}\"
#define CLING_CXX_PATH \"${CLING_CXX_PATH} ${CMAKE_CXX_FLAGS_NO_I} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}\"
#define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\"
")
endif()
else()
@ -267,22 +269,28 @@ if (UNIX)
"
#define CLING_CXX_INCL \"${CLING_CXX_HEADERS}\"
#define CLING_CXX_RLTV \"${CLING_CXX_RLTV} ${CMAKE_CXX_FLAGS_NO_I} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}\"
#define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\"
")
endif()
# Make sure this goes last so so we can pick up any changes that occured
# Also means cling-compiledata.h.in should be edited never cling-compiledata.h
else()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in
"
#define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\"
")
endif()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in
${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h
MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in
COMMENT "Updating cling-compiledata.h")
# Make sure this goes last so so we can pick up any changes that occured
# Also means cling-compiledata.h.in should be edited never cling-compiledata.h
add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/CIFactory.cpp
${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h)
add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/Interpreter.cpp
${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in
${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h
MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in
COMMENT "Updating cling-compiledata.h")
endif() # UNIX
add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/CIFactory.cpp
${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h)
add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/Interpreter.cpp
${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h)

View File

@ -8,8 +8,10 @@
//------------------------------------------------------------------------------
#include "cling/Interpreter/Interpreter.h"
#include "cling/Utils/Paths.h"
#include "ClingUtils.h"
#include "cling-compiledata.h"
#include "DynamicLookup.h"
#include "ExternalInterpreterSource.h"
#include "ForwardDeclPrinter.h"
@ -298,16 +300,10 @@ namespace cling {
void Interpreter::AddRuntimeIncludePaths(const char* argv0) {
// Add configuration paths to interpreter's include files.
#ifdef CLING_INCLUDE_PATHS
llvm::StringRef InclPaths(CLING_INCLUDE_PATHS);
for (std::pair<llvm::StringRef, llvm::StringRef> Split
= InclPaths.split(':');
!Split.second.empty(); Split = InclPaths.split(':')) {
if (llvm::sys::fs::is_directory(Split.first))
AddIncludePath(Split.first);
InclPaths = Split.second;
}
// Add remaining part
AddIncludePath(InclPaths);
llvm::SmallVector<llvm::StringRef, 6> Paths;
utils::SplitPaths(CLING_INCLUDE_PATHS, Paths);
for (llvm::StringRef Path : Paths)
AddIncludePath(Path);
#endif
llvm::SmallString<512> P(GetExecutablePath(argv0));
if (!P.empty()
@ -323,7 +319,6 @@ namespace cling {
if (llvm::sys::fs::is_directory(P.str()))
AddIncludePath(P.str());
}
}
void Interpreter::IncludeCXXRuntime() {

View File

@ -11,6 +11,7 @@ set( LLVM_LINK_COMPONENTS
add_cling_library(clingUtils OBJECT
AST.cpp
Paths.cpp
SourceNormalization.cpp
Validation.cpp

41
lib/Utils/Paths.cpp Normal file
View File

@ -0,0 +1,41 @@
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author:
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
#include "cling/Utils/Paths.h"
#include "llvm/Support/FileSystem.h"
namespace cling {
namespace utils {
bool SplitPaths(llvm::StringRef PathStr,
llvm::SmallVectorImpl<llvm::StringRef>& Paths, bool EarlyOut,
llvm::StringRef Delim) {
bool AllExisted = true;
for (std::pair<llvm::StringRef, llvm::StringRef> Split = PathStr.split(Delim);
!Split.second.empty(); Split = PathStr.split(Delim)) {
if (!llvm::sys::fs::is_directory(Split.first)) {
if (EarlyOut)
return false;
AllExisted = false;
} else
Paths.push_back(Split.first);
PathStr = Split.second;
}
// Add remaining part
if (llvm::sys::fs::is_directory(PathStr))
Paths.push_back(PathStr);
else
AllExisted = false;
return AllExisted;
}
} // namespace utils
} // namespace cling