A CMake utility to emulate VPC-style conditional file inclusion in a build system. This allows you to specify source files and associate them with platform-specific or user-defined conditions in a flexible and readable way.
- Conditional inclusion of source files using standard platform flags or custom variables
- Support for logical operations:
AND,OR, andNOT - Clean and extendable function structure
- Optional debugging output to verify which files are being included
Include vpc.cmake in your CMakeLists.txt:
include(path/to/vpc.cmake)Use vpc_file to create a conditional list of files:
vpc_file(SOURCES
src/main.cpp
src/windows_specific.cpp WIN32
src/linux_specific.cpp UNIX AND NOT APPLE
src/macos_specific.mm APPLE
src/experimental.cpp ENABLE_EXPERIMENTAL_FEATURE
)
add_executable(MyApp ${SOURCES})To print the selected files during configuration, use vpc_file_debug:
vpc_file_debug(SOURCES
src/main.cpp
src/debug_only.cpp ENABLE_DEBUG
)You can use standard CMake variables like:
WIN32UNIXAPPLEMSVC
You can also define your own conditions:
option(ENABLE_EXPERIMENTAL_FEATURE "Enable experimental features" OFF)And use them:
vpc_file(SOURCES
src/experimental.cpp ENABLE_EXPERIMENTAL_FEATURE
)