Skip to content

conan support (dependency and package manager) #342

Description

@blockspacer

Hi.

conan allows to wrap existing cmake build scripts. Conan is a dependency and package manager for C and C++ languages

Proof of concept:
https://github.com/blockspacer/cling_conan.git

My use case:
I use libtooling and cling to parse and execute C++ code at compile-time. https://github.com/blockspacer/CXXCTP

A lot of people over internet said that cant find how to integrate cling into their applications without ROOT ecosystem related to #298

That approach also allows to distribute & find cling and clang headers in project build dirs (so CXXCTP tool will be able to auto download headers without need to configure paths using command-line arguments)

Proof of concept code below allows to find & use LLVMConfig.cmake using conan package (cling requires to provide LLVMDIR):

# see https://github.com/feelpp/feelpp/tree/v0.103.1/cmake/modules/FindCling.cmake
# see https://github.com/alandefreitas/find_package_online/blob/master/Modules/FindCling.cmake
# see https://github.com/alandefreitas/find_package_online/blob/master/Modules/ExternalProjectCling.cmake

if(NOT TARGET CONAN_PKG::cling_conan)
  message(FATAL_ERROR "Use CONAN_PKG::cling_conan from conan")
endif()

message (STATUS "CONAN_CLING_CONAN_ROOT=${CONAN_CLING_CONAN_ROOT}")
message (STATUS "CONAN_LIB_DIRS_CLING_CONAN=${CONAN_LIB_DIRS_CLING_CONAN}")
message (STATUS "CONAN_BUILD_DIRS_CLING_CONAN=${CONAN_BUILD_DIRS_CLING_CONAN}")
message (STATUS "CONAN_INCLUDE_DIRS_CLING_CONAN=${CONAN_INCLUDE_DIRS_CLING_CONAN}")

find_path(CLING_Interpreter_INCLUDE_DIR ClingOptions.h
          HINTS
                ${CONAN_CLING_CONAN_ROOT}
                ${CONAN_LIB_DIRS_CLING_CONAN}
                ${CONAN_BUILD_DIRS_CLING_CONAN}
                ${CONAN_INCLUDE_DIRS_CLING_CONAN}
                ${CONAN_CLING_CONAN_ROOT}/include/cling/Interpreter
                # fallback to system one
                ${CLING_DIR}/src/tools/cling/include/cling/Interpreter
                ${CLING_DIR}/llvm_src/tools/cling/include/cling/Interpreter
                $ENV{CLING_PREFIX}/include/cling/Interpreter
                ${CLING_PREFIX}/include/cling/Interpreter
                /usr/include/cling/Interpreter
                /usr/local/include/cling/Interpreter
                /opt/local/include/cling/Interpreter
          NO_DEFAULT_PATH)

message(STATUS "[cling] CLING_Interpreter_INCLUDE_DIR: ${CLING_Interpreter_INCLUDE_DIR}")

find_path(LLVMConfig_DIR LLVMConfig.cmake
          HINTS
                ${CONAN_CLING_CONAN_ROOT}
                ${CONAN_LIB_DIRS_CLING_CONAN}
                ${CONAN_BUILD_DIRS_CLING_CONAN}
                ${CONAN_INCLUDE_DIRS_CLING_CONAN}
                ${CONAN_CLING_CONAN_ROOT}/lib/cmake/llvm
                # fallback to system one
                ${CLING_DIR}/src/tools/cling/include/cling/Interpreter
                ${CLING_DIR}/llvm_src/tools/cling/include/cling/Interpreter
                $ENV{CLING_PREFIX}/include/cling/Interpreter
                ${CLING_PREFIX}/include/cling/Interpreter
                ${CLING_Interpreter_INCLUDE_DIR}/../../../../../../build/lib/cmake/llvm
                /usr/include/cling/Interpreter
                /usr/local/include/cling/Interpreter
                /opt/local/include/cling/Interpreter
          NO_DEFAULT_PATH)

message(STATUS "[cling] LLVMConfig_DIR: ${LLVMConfig_DIR}")

include(
  ${LLVMConfig_DIR}/LLVMConfig.cmake
)

if(LLVM_BINARY_DIR)
  message(STATUS "[cling] LLVM_BINARY_DIR: ${LLVM_BINARY_DIR}")
else()
  message(FATAL_ERROR "[cling] LLVM_BINARY_DIR not found: ${LLVM_BINARY_DIR}")
endif()

list(APPEND CLING_DEFINITIONS LLVMDIR="${LLVM_BINARY_DIR}")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions