slang-compiler-sys/CMakeLists.txt

38 lines
1.7 KiB
CMake
Raw Permalink Normal View History

2024-12-28 23:24:57 -05:00
# 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)
2024-12-30 16:35:33 -05:00
project(slang-tools)
2024-12-28 23:24:57 -05:00
find_program(CXXBRIDGE cxxbridge)
2024-12-30 16:35:33 -05:00
set(SLANG_TOOLS_CXXBRIDGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge)
2024-12-28 23:24:57 -05:00
# Generate the Rust bridge stubs header
2024-12-30 16:35:33 -05:00
# 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)
2024-12-28 23:24:57 -05:00
add_custom_command(
2024-12-30 16:35:33 -05:00
OUTPUT ${SLANG_TOOLS_CXXBRIDGE_RUST}
COMMAND ${CXXBRIDGE} --header -o ${SLANG_TOOLS_CXXBRIDGE_RUST}
2024-12-28 23:24:57 -05:00
)
# Generate the Rust bridge header
# This is used by the C++ implementation to interact with Rust
2024-12-30 16:35:33 -05:00
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)
2024-12-28 23:24:57 -05:00
add_custom_command(
2024-12-30 16:35:33 -05:00
OUTPUT ${SLANG_TOOLS_CXXBRIDGE_OUTPUT}
COMMAND ${CXXBRIDGE} ${SLANG_TOOLS_CXXBRIDGE_INPUT} --header -o ${SLANG_TOOLS_CXXBRIDGE_OUTPUT}
DEPENDS ${SLANG_TOOLS_CXXBRIDGE_INPUT}
2024-12-28 23:24:57 -05:00
)
2024-12-30 16:35:33 -05:00
add_custom_target(slang_tools_bridge DEPENDS ${SLANG_TOOLS_CXXBRIDGE_RUST} ${SLANG_TOOLS_CXXBRIDGE_OUTPUT})
add_library(slang_tools "src/lib.cpp")
2024-12-28 23:24:57 -05:00
# Find the bridge headers
2024-12-30 16:35:33 -05:00
add_dependencies(slang_tools slang_tools_bridge)
target_include_directories(slang_tools PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src ${SLANG_TOOLS_CXXBRIDGE_DIR})
2024-12-28 23:24:57 -05:00
# Find the slang headers
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/slang" EXCLUDE_FROM_ALL)
2024-12-30 16:35:33 -05:00
target_link_libraries(slang_tools PRIVATE slang)