Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 27 additions & 85 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(ExternalProject)
include(GNUInstallDirs)

# This option won't make a lot of sense since we only ship the shared library in site-packages
Expand All @@ -32,63 +31,6 @@ endif()
set(CPPJIT_LLVM_VERSION_MIN 20)
set(CPPJIT_LLVM_VERSION_MAX 22)

set(_llvm_hints "")

if(DEFINED ENV{CONDA_PREFIX})
list(APPEND _llvm_hints "$ENV{CONDA_PREFIX}/lib/cmake/llvm")
endif()

if(DEFINED LLVM_DIR)
# An explicit LLVM_DIR is authoritative: fail instead of falling back to a
# different LLVM than the one requested. A failed find_package resets
# LLVM_DIR to -NOTFOUND, so keep the requested value for the message.
set(_llvm_dir_arg "${LLVM_DIR}")
find_package(LLVM CONFIG PATHS "${LLVM_DIR}" NO_DEFAULT_PATH)
if(NOT LLVM_FOUND)
message(FATAL_ERROR
"No LLVMConfig.cmake under LLVM_DIR (${_llvm_dir_arg}); expected "
"<install prefix or build tree>/lib/cmake/llvm")
endif()
else()
find_package(LLVM CONFIG QUIET HINTS ${_llvm_hints})
if(NOT LLVM_FOUND)
message(FATAL_ERROR
"No LLVM CMake package found. Install LLVM "
"${CPPJIT_LLVM_VERSION_MIN}-${CPPJIT_LLVM_VERSION_MAX} development packages "
"(apt: llvm-${CPPJIT_LLVM_VERSION_MAX}-dev libclang-${CPPJIT_LLVM_VERSION_MAX}-dev; "
"conda: llvmdev clangdev), or point cppjit at your own LLVM build with "
"-DLLVM_DIR=<prefix or build tree>/lib/cmake/llvm "
"(pip: --config-settings=cmake.define.LLVM_DIR=...)")
endif()
endif()

message(STATUS "Found LLVM ${LLVM_VERSION} at ${LLVM_DIR}")
if(LLVM_VERSION_MAJOR LESS CPPJIT_LLVM_VERSION_MIN OR
LLVM_VERSION_MAJOR GREATER CPPJIT_LLVM_VERSION_MAX)
message(FATAL_ERROR
"LLVM ${LLVM_VERSION} is unsupported: the currently supported "
"CppInterOp version (${CPPINTEROP_GIT_TAG}) only supports LLVM "
"${CPPJIT_LLVM_VERSION_MIN}-${CPPJIT_LLVM_VERSION_MAX}")
endif()

if(DEFINED Clang_DIR)
# An explicit Clang_DIR is authoritative, like LLVM_DIR above.
set(_clang_dir_arg "${Clang_DIR}")
find_package(Clang CONFIG PATHS "${Clang_DIR}" NO_DEFAULT_PATH)
if(NOT Clang_FOUND)
message(FATAL_ERROR
"No ClangConfig.cmake under Clang_DIR (${_clang_dir_arg}); expected "
"<install prefix or build tree>/lib/cmake/clang")
endif()
else()
# Clang's package sits beside LLVM's in every supported layout; search
# only there so an unrelated system clang cannot satisfy the lookup.
find_package(Clang CONFIG QUIET HINTS "${LLVM_DIR}/../clang" NO_DEFAULT_PATH)
endif()
if(Clang_FOUND)
message(STATUS "Found Clang at ${Clang_DIR}")
endif()

# CppInterOp is installed at the location cppjit ships at runtime: ask for the
# site-packages path; fall back to CMAKE_INSTALL_PREFIX for standalone builds.
execute_process(
Expand All @@ -106,7 +48,9 @@ endif()
# owns every installed file.
set(CPPINTEROP_STAGE_DIR "${CMAKE_BINARY_DIR}/cppinterop-stage")

# Include cmake for CppInterOp config and build using ExternalProject.
# Acquire CppInterOp: an external prebuilt one (CppInterOp_DIR /
# CMAKE_PREFIX_PATH), else the pinned ExternalProject. Exports the
# CPPJIT_INTEROP_* coordinates consumed below.
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/AddCppInterOp.cmake)
cppjit_add_cppinterop()

Expand All @@ -118,17 +62,19 @@ set(INTEROP_SOURCES
)

add_library(cppjit SHARED ${CPYRT_SOURCES} ${INTEROP_SOURCES})
add_dependencies(cppjit CppInterOp)
if(TARGET CppInterOp)
add_dependencies(cppjit CppInterOp)
endif()

# The wrapper anchors these relative spellings at its own load location,
# falling back to the install prefix (see cppinterop_paths()); the clang
# major names the versioned compiler probed for the runtime resource dir.
# The wrapper anchors these coordinates at its own load location, falling
# back to the install prefix (see cppinterop_paths()); the clang major
# names the versioned compiler probed for the runtime resource dir.
target_compile_definitions(cppjit PRIVATE
CPPINTEROP_INSTALL_PREFIX="${CPPINTEROP_INSTALL_PREFIX}/cppjit"
CPPINTEROP_LIBRARY="interop/lib/libclangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}"
CPPINTEROP_INCLUDE_DIR="interop/include"
CPPJIT_CLANG_MAJOR="${LLVM_VERSION_MAJOR}"
CPPJIT_CLANG_INCLUDE_DIR="interop/lib/clang/${LLVM_VERSION_MAJOR}"
CPPINTEROP_LIBRARY="${CPPJIT_INTEROP_LIBRARY}"
CPPINTEROP_INCLUDE_DIR="${CPPJIT_INTEROP_RUNTIME_INCLUDES}"
CPPJIT_CLANG_MAJOR="${CPPJIT_INTEROP_CLANG_MAJOR}"
CPPJIT_CLANG_INCLUDE_DIR="${CPPJIT_INTEROP_CLANG_DIR}"
)

target_include_directories(cppjit PRIVATE
Expand All @@ -137,7 +83,7 @@ target_include_directories(cppjit PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/cpyrt
${CMAKE_CURRENT_SOURCE_DIR}/src/interop
${CPPINTEROP_STAGE_DIR}/include
${CPPJIT_INTEROP_COMPILE_INCLUDES}
${Python_INCLUDE_DIRS}
)

Expand Down Expand Up @@ -167,24 +113,20 @@ install(TARGETS cppjit
LIBRARY DESTINATION cppjit
)

install(DIRECTORY "${CPPINTEROP_STAGE_DIR}/lib/"
DESTINATION cppjit/interop/lib
)
install(DIRECTORY "${CPPINTEROP_STAGE_DIR}/include/"
DESTINATION cppjit/interop/include
)

# ship the builtin headers of the build clang, laid out as a headers-only
# resource dir: only include/ ships
set(_clang_resource_dir "${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION_MAJOR}")
if(NOT EXISTS "${_clang_resource_dir}/include")
message(FATAL_ERROR
"No builtin headers at ${_clang_resource_dir}/include; the LLVM at "
"${LLVM_DIR} carries no clang resource directory")
# An external CppInterOp is consumed in place and nothing of it ships;
# the bundled one installs with the builtin headers of the build clang,
# laid out as a headers-only resource dir (only include/ ships).
if(TARGET CppInterOp)
install(DIRECTORY "${CPPINTEROP_STAGE_DIR}/lib/"
DESTINATION cppjit/interop/lib
)
install(DIRECTORY "${CPPINTEROP_STAGE_DIR}/include/"
DESTINATION cppjit/interop/include
)
install(DIRECTORY "${CPPJIT_INTEROP_CLANG_RESOURCE_DIR}/include/"
DESTINATION "cppjit/interop/lib/clang/${CPPJIT_INTEROP_CLANG_MAJOR}/include"
)
endif()
install(DIRECTORY "${_clang_resource_dir}/include/"
DESTINATION "cppjit/interop/lib/clang/${LLVM_VERSION_MAJOR}/include"
)

# the public cpyrt API headers keep their installed cpyrt/ prefix
install(FILES
Expand Down
Loading
Loading