Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] Enable building clad within the LLVM monorepo. #1157

Merged
merged 1 commit into from
Nov 30, 2024
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
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,38 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)

set( CLAD_BUILT_STANDALONE 1 )
else()
# Not standalone; we are building within llvm
if (NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)
message(FATAL_ERROR "Clang is not enabled; consider enabling it in LLVM_ENABLED_PROJECTS")
endif()

message(STATUS "Building Clad as part of LLVM")

# Try finding the LLVMConfig.cmake if we build against prebuilt LLVM
set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
if(EXISTS ${LLVMCONFIG_FILE})
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
include(${LLVMCONFIG_FILE})
endif()

if (NOT CLANG_INCLUDE_DIRS)
set (CLANG_INCLUDE_DIRS "${LLVM_MAIN_SRC_DIR}/tools/clang/include")
if (NOT EXISTS ${CLANG_INCLUDE_DIRS})
# Otherwise assume the monorepo layout.
set (CLANG_INCLUDE_DIRS ${LLVM_MAIN_SRC_DIR}/../clang/include )
endif()
set (CLANG_INCLUDE_DIRS "${CLANG_INCLUDE_DIRS}" "${LLVM_BINARY_DIR}/tools/clang/include")
endif()
if (NOT LLVM_INCLUDE_DIRS)
set (LLVM_INCLUDE_DIRS "${LLVM_MAIN_SRC_DIR}/include" "${LLVM_BINARY_DIR}/include")
endif()
endif()

include_directories(SYSTEM ${CLANG_INCLUDE_DIRS})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})

## Code Coverage Configuration
add_library(coverage_config INTERFACE)
option(CLAD_CODE_COVERAGE "Enable coverage reporting" OFF)
Expand Down
6 changes: 6 additions & 0 deletions cmake/modules/AddClad.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ function(ENABLE_CLAD_FOR_TARGET executable)
set_property(TARGET ${executable} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

add_dependencies(${executable} clad)

# We are probably building clad with clang.
if (NOT CLAD_BUILT_STANDALONE)
add_dependencies(${executable} clad)
endif()

# If clad.so changes we don't need to relink but to rebuild the source files.
# $<TARGET_FILE:clad> does not work for OBJECT_DEPENDS.
set (CLAD_SO_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/clad${CMAKE_SHARED_LIBRARY_SUFFIX}")
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/CladGoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(_gtest_byproduct_binary_dir
${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build)
${CLAD_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build)
set(_gtest_byproducts
${_gtest_byproduct_binary_dir}/lib/libgtest.a
${_gtest_byproduct_binary_dir}/lib/libgtest_main.a
Expand Down
Loading