slang-compiler-sys/CMakeLists.txt

38 lines
1.7 KiB
CMake

# NOTE: This file is _not_ used as part of the main build process.
# It exists to help IDE tools provide auto-hinting while developing the C++ bridge
cmake_minimum_required(VERSION 3.22)
project(slang-tools)
find_program(CXXBRIDGE cxxbridge)
set(SLANG_TOOLS_CXXBRIDGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge)
# Generate the Rust bridge stubs header
# This is used by the C++ header while defining the interface for Rust
file(MAKE_DIRECTORY ${SLANG_TOOLS_CXXBRIDGE_DIR}/rust)
set(SLANG_TOOLS_CXXBRIDGE_RUST ${SLANG_TOOLS_CXXBRIDGE_DIR}/rust/cxx.h)
add_custom_command(
OUTPUT ${SLANG_TOOLS_CXXBRIDGE_RUST}
COMMAND ${CXXBRIDGE} --header -o ${SLANG_TOOLS_CXXBRIDGE_RUST}
)
# Generate the Rust bridge header
# This is used by the C++ implementation to interact with Rust
file(MAKE_DIRECTORY ${SLANG_TOOLS_CXXBRIDGE_DIR}/slang-tools/src)
set(SLANG_TOOLS_CXXBRIDGE_INPUT ${CMAKE_CURRENT_LIST_DIR}/src/lib.rs)
set(SLANG_TOOLS_CXXBRIDGE_OUTPUT ${SLANG_TOOLS_CXXBRIDGE_DIR}/slang-tools/src/lib.rs.h)
add_custom_command(
OUTPUT ${SLANG_TOOLS_CXXBRIDGE_OUTPUT}
COMMAND ${CXXBRIDGE} ${SLANG_TOOLS_CXXBRIDGE_INPUT} --header -o ${SLANG_TOOLS_CXXBRIDGE_OUTPUT}
DEPENDS ${SLANG_TOOLS_CXXBRIDGE_INPUT}
)
add_custom_target(slang_tools_bridge DEPENDS ${SLANG_TOOLS_CXXBRIDGE_RUST} ${SLANG_TOOLS_CXXBRIDGE_OUTPUT})
add_library(slang_tools "src/lib.cpp")
# Find the bridge headers
add_dependencies(slang_tools slang_tools_bridge)
target_include_directories(slang_tools PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src ${SLANG_TOOLS_CXXBRIDGE_DIR})
# Find the slang headers
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/slang" EXCLUDE_FROM_ALL)
target_link_libraries(slang_tools PRIVATE slang)