Export `luisa-config.h` and pkg-config file for non-CMake build systems
Overview
This PR adds support for using LuisaCompute with build systems other than CMake by generating and installing a configuration header (luisa-config.h) and a pkg-config file (luisacompute.pc) during CMake installation.
Motivation
Users who want to integrate LuisaCompute into projects using build systems like Make, Bazel, Meson, or others need access to the compile-time configuration that CMake normally handles automatically. This PR addresses that need by exporting configuration information in standard formats.
Changes
New Files
-
include/luisa/luisa-config.h.in- Template for the configuration header containing:- Version information via inclusion of existing
version.hheader - Core feature flags (
LUISA_ENABLE_IR,LUISA_ENABLE_DSL,LUISA_ENABLE_GUI,LUISA_ENABLE_API,LUISA_ENABLE_XIR,LUISA_ENABLE_CLANGCXX,LUISA_ENABLE_TENSOR) - Platform detection macros (
LUISA_PLATFORM_WINDOWS,LUISA_PLATFORM_UNIX,LUISA_PLATFORM_APPLE) - Platform-specific features (
LUISA_ENABLE_WAYLAND) - System library usage flags (
LUISA_USE_SYSTEM_STL,LUISA_USE_SYSTEM_SPDLOG,LUISA_USE_SYSTEM_XXHASH,LUISA_USE_SYSTEM_MAGIC_ENUM,LUISA_USE_SYSTEM_GLFW,LUISA_USE_SYSTEM_REPROC,LUISA_USE_SYSTEM_YYJSON,LUISA_USE_SYSTEM_MARL,LUISA_USE_SYSTEM_LMDB,LUISA_USE_SYSTEM_VULKAN) - Compiler feature requirements (
LUISA_COMPUTE_C_STANDARD,LUISA_COMPUTE_CXX_STANDARD)
- Version information via inclusion of existing
-
luisacompute.pc.in- pkg-config template providing:- Package metadata (name, description, version, URL)
- Compiler flags with all relevant compile definitions
- Library paths for linking
Modified Files
-
CMakeLists.txt:- Systematically collects all compile definitions from CMake configuration options
- Uses helper function for elegant pkg-config flag population
- Generates
luisa-config.handluisacompute.pcduring configuration - Installs both files to appropriate locations (
<prefix>/include/luisa/and<prefix>/lib/pkgconfig/) - Adds generated include directory to build interface
-
BUILD.md:- Added "Using LuisaCompute with Other Build Systems" section
- Documents the configuration header and its macros
- Provides pkg-config usage examples
- Includes Makefile integration example
Usage
After installing LuisaCompute with CMake:
cmake --install <build-dir> --prefix /path/to/install
Users can now:
Include the configuration header:
#include <luisa/luisa-config.h>
#if LUISA_ENABLE_DSL
// Use DSL features
#endif
Use pkg-config for build configuration:
# Get compiler flags
pkg-config --cflags luisacompute
# Get linker flags
pkg-config --libs luisacompute
# Use in a Makefile
CXXFLAGS += $(shell pkg-config --cflags luisacompute)
LDFLAGS += $(shell pkg-config --libs luisacompute)
Testing
Verified that:
- Configuration files are correctly generated with different CMake options (DSL enabled/disabled, system libraries, different platforms)
- All compile definitions are properly collected and exported
- Generated files are properly installed during
cmake --install - pkg-config integration works correctly with all flags
- C++ programs can successfully compile using the exported configuration
- Version information is correctly pulled from existing
version.hheader
Fixes #117
Original prompt
This section details on the original issue you should resolve
<issue_title>Export
luisa-config.hfor other build systems than CMake</issue_title> <issue_description>So we can better support the use cases like in LuisaGroup/LuisaCompute#117.</issue_description><agent_instructions>collect compile definitions and options in CMakeLists and generate luisa-config.h on CMake install, and optionally a pkg-config file with proper compile and link flags</agent_instructions>
Comments on the Issue (you are @copilot in this section)
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
@copilot Please fix this.
The flags look not fully collected. Please review all CMakeLists including those in the subdirectory. Also, you might notice that there is already a version header under the include dir so dont repeat...
Fixed in commit 8c59a33. Changes:
- luisa-config.h now includes version.h instead of duplicating version macros
- Added all LUISA_ENABLE_* flags (IR, DSL, GUI, API, XIR, CLANGCXX, TENSOR)
- Added all LUISA_USE_SYSTEM_* flags (STL, SPDLOG, XXHASH, MAGIC_ENUM, GLFW, REPROC, YYJSON, MARL, LMDB, VULKAN)
- Added all platform flags (WINDOWS, UNIX, APPLE, WAYLAND)
- Used a helper function to cleanly populate pkg-config flags
@copilot Please fix this.
Fixed in d46f695.