Skip to content

Commit aa8a0ee

Browse files
authored
Hybrid single example (#173)
1 parent 0495a9c commit aa8a0ee

File tree

9 files changed

+137
-0
lines changed

9 files changed

+137
-0
lines changed

.github/workflows/linux_gcc_cmake_build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ jobs:
9191
cmake --build build --parallel 2 --config Release
9292
./build/Release/build
9393
94+
- name: Hybrid Single Example
95+
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}}
96+
run: |
97+
cmake --build . --target run_hybrid_single_example --config Release
98+
9499
- name: Hybrid Simple Example
95100
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}}
96101
run: |
@@ -214,6 +219,11 @@ jobs:
214219
cmake --build build --parallel 2 --config Release
215220
./build/Release/build
216221
222+
- name: Hybrid Single Example
223+
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
224+
run: |
225+
cmake --build . --target run_hybrid_single_example --config Release
226+
217227
- name: Hybrid Simple Example
218228
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
219229
run: |

.github/workflows/win_cmake_build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ jobs:
8888
ls
8989
.\build.exe
9090
91+
- name: Hybrid Single Example
92+
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
93+
run: |
94+
cmake --build . --config Release --parallel 2 --target run_hybrid_single_example
95+
9196
- name: Hybrid Simple Example
9297
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
9398
run: |
@@ -178,6 +183,11 @@ jobs:
178183
ls
179184
.\build.exe
180185
186+
- name: Hybrid Single Example
187+
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_CLANG_DEV_ALL}}
188+
run: |
189+
cmake --build . --target run_hybrid_single_example --config Release
190+
181191
- name: Hybrid Simple Example
182192
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_CLANG_DEV_ALL}}
183193
run: |

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ if (${BUILDCC_INSTALL})
106106
endif()
107107

108108
if (${BUILDCC_EXAMPLES})
109+
add_subdirectory(example/hybrid/single)
109110
add_subdirectory(example/hybrid/simple)
110111
add_subdirectory(example/hybrid/foolib)
111112
add_subdirectory(example/hybrid/external_lib)

example/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Multi hosts and multi targets
108108

109109
**Current state of examples**
110110

111+
- [x] Single
112+
- Compile a single source with `Register` and `Args` module
111113
- [x] Simple
112114
- Similar to Flags example with `Register` and `Args` module
113115
- [x] Foolib

example/hybrid/single/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Folder
2+
generated
3+
buildcc
4+
_internal*
5+
6+
# Files
7+
*.exe
8+
*.o
9+
*.bin
10+
*.dot

example/hybrid/single/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 3.10.0)
2+
set(CMAKE_CXX_STANDARD 17)
3+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5+
project(hybrid_single_example)
6+
7+
# Bootstrap your build file using CMake
8+
add_executable(hybrid_single_example build.cpp)
9+
target_link_libraries(hybrid_single_example PRIVATE buildcc)
10+
11+
# TODO, Add this only if MINGW is used
12+
# https://github.com/msys2/MINGW-packages/issues/2303
13+
# Similar issue when adding the Taskflow library
14+
if (${MINGW})
15+
message(WARNING "-Wl,--allow-multiple-definition for MINGW")
16+
target_link_options(hybrid_single_example PRIVATE -Wl,--allow-multiple-definition)
17+
endif()
18+
19+
# Run your build file
20+
add_custom_target(run_hybrid_single_example
21+
COMMAND hybrid_single_example --help-all
22+
COMMAND hybrid_single_example --config ${CMAKE_CURRENT_SOURCE_DIR}/build.toml
23+
# COMMAND dot -Tpng graph.dot -o graph.PNG
24+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
25+
DEPENDS hybrid_single_example buildcc
26+
VERBATIM USES_TERMINAL
27+
)

example/hybrid/single/build.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "buildcc.h"
2+
3+
using namespace buildcc;
4+
5+
constexpr const char *const EXE = "build";
6+
7+
// Function Prototypes
8+
static void clean_cb();
9+
static void hello_world_build_cb(BaseTarget &target);
10+
11+
int main(int argc, char **argv) {
12+
// 1. Get arguments
13+
Args args;
14+
ArgToolchain arg_gcc;
15+
args.AddToolchain("gcc", "Generic gcc toolchain", arg_gcc);
16+
args.Parse(argc, argv);
17+
18+
// 2. Initialize your environment
19+
Register reg(args);
20+
21+
// 3. Pre-build steps
22+
reg.Clean(clean_cb);
23+
24+
// 4. Build steps
25+
// Explicit toolchain - target pairs
26+
Toolchain_gcc gcc;
27+
ExecutableTarget_gcc hello_world("hello_world", gcc, "");
28+
auto verified_toolchains = gcc.Verify();
29+
env::assert_fatal(!verified_toolchains.empty(), "GCC Toolchain not found");
30+
31+
// Select your builds and tests using the .toml files
32+
reg.Build(arg_gcc.state, hello_world_build_cb, hello_world);
33+
34+
// 5. Test steps
35+
reg.Test(arg_gcc.state, "{executable}", hello_world);
36+
37+
// 6. Build Target
38+
reg.RunBuild();
39+
40+
// 7. Test Target
41+
reg.RunTest();
42+
43+
// 8. Post Build steps
44+
// - Clang Compile Commands
45+
plugin::ClangCompileCommands({&hello_world}).Generate();
46+
47+
return 0;
48+
}
49+
50+
static void clean_cb() {
51+
env::log_info(EXE, fmt::format("Cleaning {}", env::get_project_build_dir()));
52+
fs::remove_all(env::get_project_build_dir());
53+
}
54+
55+
static void hello_world_build_cb(BaseTarget &target) {
56+
target.AddSource("main.cpp", "src");
57+
58+
target.Build();
59+
}

example/hybrid/single/build.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Root
2+
root_dir = ""
3+
build_dir = "_build"
4+
loglevel = "trace"
5+
6+
# Project
7+
clean = true
8+
9+
# Toolchain
10+
[toolchain.gcc]
11+
build = true
12+
test = true

example/hybrid/single/src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <iostream>
2+
3+
int main() {
4+
std::cout << "Hello World" << std::endl;
5+
return 0;
6+
}

0 commit comments

Comments
 (0)