diff --git a/.github/workflows/linux_gcc_cmake_build.yml b/.github/workflows/linux_gcc_cmake_build.yml index 304f38a2..e694565d 100644 --- a/.github/workflows/linux_gcc_cmake_build.yml +++ b/.github/workflows/linux_gcc_cmake_build.yml @@ -91,6 +91,11 @@ jobs: cmake --build build --parallel 2 --config Release ./build/Release/build + - name: Hybrid Single Example + working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}} + run: | + cmake --build . --target run_hybrid_single_example --config Release + - name: Hybrid Simple Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}} run: | @@ -214,6 +219,11 @@ jobs: cmake --build build --parallel 2 --config Release ./build/Release/build + - name: Hybrid Single Example + working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}} + run: | + cmake --build . --target run_hybrid_single_example --config Release + - name: Hybrid Simple Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}} run: | diff --git a/.github/workflows/win_cmake_build.yml b/.github/workflows/win_cmake_build.yml index 7a898da1..badc6173 100644 --- a/.github/workflows/win_cmake_build.yml +++ b/.github/workflows/win_cmake_build.yml @@ -88,6 +88,11 @@ jobs: ls .\build.exe + - name: Hybrid Single Example + working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} + run: | + cmake --build . --config Release --parallel 2 --target run_hybrid_single_example + - name: Hybrid Simple Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | @@ -178,6 +183,11 @@ jobs: ls .\build.exe + - name: Hybrid Single Example + working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_CLANG_DEV_ALL}} + run: | + cmake --build . --target run_hybrid_single_example --config Release + - name: Hybrid Simple Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_CLANG_DEV_ALL}} run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index e1f660af..68e47918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ if (${BUILDCC_INSTALL}) endif() if (${BUILDCC_EXAMPLES}) + add_subdirectory(example/hybrid/single) add_subdirectory(example/hybrid/simple) add_subdirectory(example/hybrid/foolib) add_subdirectory(example/hybrid/external_lib) diff --git a/example/README.md b/example/README.md index ad046da9..eafe6468 100644 --- a/example/README.md +++ b/example/README.md @@ -108,6 +108,8 @@ Multi hosts and multi targets **Current state of examples** +- [x] Single + - Compile a single source with `Register` and `Args` module - [x] Simple - Similar to Flags example with `Register` and `Args` module - [x] Foolib diff --git a/example/hybrid/single/.gitignore b/example/hybrid/single/.gitignore new file mode 100644 index 00000000..cb283a9c --- /dev/null +++ b/example/hybrid/single/.gitignore @@ -0,0 +1,10 @@ +# Folder +generated +buildcc +_internal* + +# Files +*.exe +*.o +*.bin +*.dot diff --git a/example/hybrid/single/CMakeLists.txt b/example/hybrid/single/CMakeLists.txt new file mode 100644 index 00000000..f5e60dca --- /dev/null +++ b/example/hybrid/single/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.10.0) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +project(hybrid_single_example) + +# Bootstrap your build file using CMake +add_executable(hybrid_single_example build.cpp) +target_link_libraries(hybrid_single_example PRIVATE buildcc) + +# TODO, Add this only if MINGW is used +# https://github.com/msys2/MINGW-packages/issues/2303 +# Similar issue when adding the Taskflow library +if (${MINGW}) + message(WARNING "-Wl,--allow-multiple-definition for MINGW") + target_link_options(hybrid_single_example PRIVATE -Wl,--allow-multiple-definition) +endif() + +# Run your build file +add_custom_target(run_hybrid_single_example + COMMAND hybrid_single_example --help-all + COMMAND hybrid_single_example --config ${CMAKE_CURRENT_SOURCE_DIR}/build.toml + # COMMAND dot -Tpng graph.dot -o graph.PNG + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS hybrid_single_example buildcc + VERBATIM USES_TERMINAL +) diff --git a/example/hybrid/single/build.cpp b/example/hybrid/single/build.cpp new file mode 100644 index 00000000..a3d00858 --- /dev/null +++ b/example/hybrid/single/build.cpp @@ -0,0 +1,59 @@ +#include "buildcc.h" + +using namespace buildcc; + +constexpr const char *const EXE = "build"; + +// Function Prototypes +static void clean_cb(); +static void hello_world_build_cb(BaseTarget &target); + +int main(int argc, char **argv) { + // 1. Get arguments + Args args; + ArgToolchain arg_gcc; + args.AddToolchain("gcc", "Generic gcc toolchain", arg_gcc); + args.Parse(argc, argv); + + // 2. Initialize your environment + Register reg(args); + + // 3. Pre-build steps + reg.Clean(clean_cb); + + // 4. Build steps + // Explicit toolchain - target pairs + Toolchain_gcc gcc; + ExecutableTarget_gcc hello_world("hello_world", gcc, ""); + auto verified_toolchains = gcc.Verify(); + env::assert_fatal(!verified_toolchains.empty(), "GCC Toolchain not found"); + + // Select your builds and tests using the .toml files + reg.Build(arg_gcc.state, hello_world_build_cb, hello_world); + + // 5. Test steps + reg.Test(arg_gcc.state, "{executable}", hello_world); + + // 6. Build Target + reg.RunBuild(); + + // 7. Test Target + reg.RunTest(); + + // 8. Post Build steps + // - Clang Compile Commands + plugin::ClangCompileCommands({&hello_world}).Generate(); + + return 0; +} + +static void clean_cb() { + env::log_info(EXE, fmt::format("Cleaning {}", env::get_project_build_dir())); + fs::remove_all(env::get_project_build_dir()); +} + +static void hello_world_build_cb(BaseTarget &target) { + target.AddSource("main.cpp", "src"); + + target.Build(); +} diff --git a/example/hybrid/single/build.toml b/example/hybrid/single/build.toml new file mode 100644 index 00000000..d849a6ef --- /dev/null +++ b/example/hybrid/single/build.toml @@ -0,0 +1,12 @@ +# Root +root_dir = "" +build_dir = "_build" +loglevel = "trace" + +# Project +clean = true + +# Toolchain +[toolchain.gcc] +build = true +test = true diff --git a/example/hybrid/single/src/main.cpp b/example/hybrid/single/src/main.cpp new file mode 100644 index 00000000..147d50de --- /dev/null +++ b/example/hybrid/single/src/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello World" << std::endl; + return 0; +}