Flextool
C++ compile-time programming (serialization, reflection, code modification, enum to string, better enum, enum to json, extend or parse language, etc.)
Install / Use
/learn @blockspacer/FlextoolREADME
<p align="center"> <a href="https://blockspacer.github.io/flex_docs"> <img src="https://blockspacer.github.io/flex_docs/images/logo.png" width="100px" alt="flextool" /> </a> </p> <h3 align="center">Add custom features to C++ language, like <a href="https://www.fluentcpp.com/2018/03/09/c-metaclasses-proposal-less-5-minutes/">metaclasses</a>, <a href="https://twitter.com/TartanLlama/status/1159457033441165313">Rust-like traits</a>, reflection and many more</h3> <p align="center">A fully open source, powerful solution for modification and generation of C++ source code. Reduce the amount of boilerplate code in your C++ projects.</p> <hr />
Main project page: https://blockspacer.github.io/flex_docs/
Tutorials and examples
Supported platforms
Tested on Ubuntu 20.04.2 LTS.
May work on other platforms with minor modifications.
Before installation: Add conan remotes
To be able to add the list of dependency remotes please type the following command:
cmake -E time conan config install conan/remotes/
# OR:
# cmake -E time conan config install conan/remotes_disabled_ssl/
Before installation
-
conan packages
NOTE: cling with LLVM build may take couple of hours.
Command below uses --profile clang12_compiler12_compiler.
Example conan profile ~/.conan/profiles/clang:
[settings]
# We are building in Ubuntu Linux
os_build=Linux
os=Linux
arch_build=x86_64
arch=x86_64
compiler=clang
compiler.version=10
compiler.libcxx=libstdc++11
[env]
CC=/usr/bin/clang-10
CXX=/usr/bin/clang++-10
[build_requires]
cmake_installer/3.15.5@conan/stable
Create clang12_compiler profile:
[settings]
# We are building in Ubuntu Linux
os_build=Linux
os=Linux
arch_build=x86_64
arch=x86_64
compiler=clang
compiler.version=12
compiler.libcxx=libstdc++11
compiler.cppstd=17
llvm_9:build_type=Release
[env]
CC=/usr/bin/clang-12
CXX=/usr/bin/clang++-12
[build_requires]
cmake_installer/3.15.5@conan/stable
Before creation of conan profile file, see: https://docs.conan.io/en/latest/using_packages/using_profiles.html.
We use .cmake script to download and install conan packages.
git clone https://github.com/blockspacer/conan_github_downloader.git ~/conan_github_downloader
cmake \
-DSCRIPT_PATH="$PWD/get_conan_dependencies.cmake"\
-DENABLE_CLING=TRUE\
-DENABLE_LLVM=TRUE\
-DENABLE_LLVM_INSTALLER=FALSE\
-DEXTRA_CONAN_OPTS="--profile;clang12_compiler\
;-s;build_type=Debug\
;-s;cling_conan:build_type=Release\
;-s;llvm_12:build_type=Release\
;--build;missing" \
-P ~/conan_github_downloader/conan_github_downloader.cmake
# clean build cache
conan remove "*" --build --force
Easy install with common plugins
If you want to install flextool and its plugins in single command, change the options provided to tools/buildConanThirdparty.cmake.
NOTE: tools/buildConanThirdparty.cmake will perform a FULL RE-BUILD; it may take couple of hours.
Command below uses --profile clang12_compiler12_compiler. Before creation of conan profile file, see: https://docs.conan.io/en/latest/using_packages/using_profiles.html.
We use buildConanThirdparty.cmake script to download and install conan packages.
NOTE: set -DENABLE_CLING=FALSE if you already installed Cling using tools/buildConanThirdparty.cmake above.
git clone https://github.com/blockspacer/conan_github_downloader.git ~/conan_github_downloader
cmake \
-DSCRIPT_PATH="$PWD/get_conan_dependencies.cmake"\
-DENABLE_CLING=TRUE\
-DENABLE_LLVM=TRUE\
-DENABLE_LLVM_INSTALLER=FALSE\
-DENABLE_FLEXTOOL=TRUE \
-DENABLE_BASIS_PLUGIN_HELPER=TRUE \
-DENABLE_FLEX_REFLECT_PLUGIN=TRUE \
-DENABLE_SQUARETS=TRUE \
-DENABLE_FLEX_SQUARETS_PLUGIN=TRUE \
-DENABLE_FLEX_PIMPL_PLUGIN=TRUE \
-DENABLE_FLEX_TYPECLASS_PLUGIN=TRUE \
-DENABLE_FLEX_META_PLUGIN=TRUE \
-DENABLE_FLEX_META_DEMO=TRUE \
-DEXTRA_CONAN_OPTS="--profile;clang12_compiler\
;-s;build_type=Debug\
;-s;cling_conan:build_type=Release\
;-s;llvm_12:build_type=Release\
;--build;missing" \
-P ~/conan_github_downloader/conan_github_downloader.cmake
# clean build cache
conan remove "*" --build --force
Installation (without plugins)
Use command below to re-build flextool (plugins must be installed separately).
Command below uses --profile clang12_compiler12_compiler. Before creation of conan profile file, see: https://docs.conan.io/en/latest/using_packages/using_profiles.html
export VERBOSE=1
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
# NOTE: change `build_type=Debug` to `build_type=Release` in production
# NOTE: use --build=missing if you got error `ERROR: Missing prebuilt package`
cmake -E time \
conan create . conan/stable \
-s build_type=Debug \
-s cling_conan:build_type=Release \
-s llvm_tools:build_type=Release \
--profile clang12_compiler \
-e flextool:enable_tests=True \
-e flextool:enable_llvm_tools=True
# clean build cache
conan remove "*" --build --force
NOTE: flextool not compatible with compile_commands.json
Disable generation of compilation database when you use flextool.
If you are using CMake, set CMAKE_EXPORT_COMPILE_COMMANDS to FALSE.
If compile_commands.json exists in build folder (or in parent folder), flextool may fail.
Standing on the Shoulders of Giants
This project is possible because of flexferrum's autoprogrammer.
Articles about flexferrum's autoprogrammer in media:
- [RUS] (article) metaclasses https://habr.com/ru/article/448466/
- [RUS] (slides) C++17 metaclasses https://assets.ctfassets.net/oxjq45e8ilak/55bGdX2PnYzmrpM8rwCjcE/791e7eee3236c2023e86e169faca8a0e/Sergei_Sadovnikov_Metaclasses_in_C___dream_Reality.pdf
Dev-only build (local conan flow)
find . -type f -name "*_buildflags.h" -exec rm {} \;
find . -type f -name "*_buildflags.tmp" -exec rm {} \;
(rm -rf local_build || true)
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
export PKG_NAME=flextool/master@conan/stable
(CONAN_REVISIONS_ENABLED=1 \
conan remove --force $PKG_NAME || true)
# NOTE: use --build=missing if you got error `ERROR: Missing prebuilt package`
cmake -E time \
conan install . \
--install-folder local_build \
-s build_type=Debug \
-s cling_conan:build_type=Release \
-s llvm_12:build_type=Release \
-o openssl:shared=True \
-e basis:enable_tests=True \
-o chromium_base:shared=True \
-e chromium_base:enable_tests=True \
-o perfetto:is_hermetic_clang=False \
--profile clang12_compiler \
-e flexlib:enable_tests=True \
-o flexlib:shared=False \
-o perfetto:is_hermetic_clang=False \
-o flexlib:enable_cling=True \
-e flextool:enable_tests=True \
-o flextool:enable_cling=True
(rm local_build/CMakeCache.txt || true)
cmake -E time \
conan source . \
--source-folder . \
--install-folder local_build
# You can use `cmake --build . -- -j14` on second run.
cmake -E time \
conan build . \
--build-folder local_build \
--source-folder . \
--install-folder local_build
conan package . \
--build-folder local_build \
--package-folder local_build/package_dir \
--source-folder . \
--install-folder local_build
cmake -E time \
conan export-pkg . conan/stable \
--package-folder local_build/package_dir \
-s build_type=Debug \
--force \
-s cling_conan:bu
