Skip to content

Hybrid single example #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/linux_gcc_cmake_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/win_cmake_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions example/hybrid/single/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Folder
generated
buildcc
_internal*

# Files
*.exe
*.o
*.bin
*.dot
27 changes: 27 additions & 0 deletions example/hybrid/single/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
59 changes: 59 additions & 0 deletions example/hybrid/single/build.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
12 changes: 12 additions & 0 deletions example/hybrid/single/build.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Root
root_dir = ""
build_dir = "_build"
loglevel = "trace"

# Project
clean = true

# Toolchain
[toolchain.gcc]
build = true
test = true
6 changes: 6 additions & 0 deletions example/hybrid/single/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello World" << std::endl;
return 0;
}