Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf54bbf0

Browse files
authored
Update lowlevel examples (#177)
1 parent6d44313 commitf54bbf0

File tree

28 files changed

+1111
-202
lines changed

28 files changed

+1111
-202
lines changed

‎buildcc/targets/include/targets/target_msvc.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,15 @@ class DynamicTarget_msvc : public BaseTarget {
126126
DynamicTarget_msvc(const std::string &name,const BaseToolchain &toolchain,
127127
const TargetEnv &env,
128128
const TargetConfig &config = MsvcConfig::DynamicLib())
129-
: Target(name, TargetType::DynamicLibrary, toolchain, env, config) {
129+
: Target(name, TargetType::DynamicLibrary, toolchain, env, config),
130+
dll_(fmt::format("{}.dll", GetTargetPath().string())) {
130131
DefaultMsvcOptions(*this);
131132
}
133+
134+
const fs::path &GetDllPath() {return dll_; }
135+
136+
private:
137+
fs::path dll_;
132138
};
133139

134140
}// namespace buildcc

‎docs/source/arch/testing.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ args
143143
plugins
144144
^^^^^^^^
145145

146-
.. note: Incomplete implementation and tests
146+
..note::Incomplete implementation and tests

‎docs/source/examples/clang.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Clang
2+
======
3+
4+
Lowlevel Clang Tests

‎docs/source/examples/gcc.rst‎

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
GCC
2+
====
3+
4+
Lowlevel GCC Tests
5+
6+
Simple
7+
--------
8+
9+
Compile a single source
10+
11+
..code-block::cpp
12+
:linenos:
13+
:emphasize-lines: 8
14+
15+
// GCC specialized toolchain
16+
Toolchain_gcc toolchain;
17+
18+
// GCC specialized targets
19+
// Create "Simple" target (meant to use the GCC compiler)
20+
// On Windows the equivalent is the MinGW compiler
21+
ExecutableTarget_gcc target("Simple", gcc, "");
22+
target.AddSource("main.cpp");
23+
target.Build();
24+
25+
// Build
26+
tf::Executor executor;
27+
executor.run(target.GetTaskflow());
28+
executor.wait_for_all();
29+
30+
31+
IncludeDir
32+
----------
33+
34+
Compile multiple sources with header files
35+
36+
..code-block::cpp
37+
:linenos:
38+
:emphasize-lines: 12,15
39+
40+
// GCC specialized toolchain
41+
Toolchain_gcc toolchain;
42+
43+
// GCC specialized targets
44+
// Create "IncludeDir" target (meant to use the GCC compiler)
45+
// On Windows the equivalent is the MinGW compiler
46+
ExecutableTarget_gcc target("IncludeDir", gcc, "files");
47+
target.AddSource("main.cpp", "src");
48+
target.AddSource("src/random.cpp");
49+
50+
// Track header for rebuilds
51+
target.AddHeader("include/random.h");
52+
53+
// Add include dir to search paths
54+
target.AddIncludeDir("include");
55+
target.Build();
56+
57+
// Build
58+
tf::Executor executor;
59+
executor.run(target.GetTaskflow());
60+
executor.wait_for_all();
61+
62+
StaticLib
63+
----------
64+
65+
Compile a static library which is used by an executable
66+
67+
..code-block::cpp
68+
:linenos:
69+
:emphasize-lines: 7
70+
71+
// GCC specialized toolchain
72+
Toolchain_gcc toolchain;
73+
74+
// GCC specialized targets
75+
// Create "librandom.a" target (meant to use the GCC compiler)
76+
// On Windows the equivalent is the MinGW compiler
77+
StaticTarget_gcc statictarget("librandom", gcc, "files");
78+
statictarget.AddSource("src/random.cpp");
79+
statictarget.AddHeader("include/random.h");
80+
statictarget.AddIncludeDir("include");
81+
statictarget.Build();
82+
83+
// GCC specialized targets
84+
// Create "statictest" target (meant to use the GCC compiler)
85+
// On Windows the equivalent is the MinGW compiler
86+
ExecutableTarget_gcc exetarget("statictest", gcc, "files");
87+
exetarget.AddSource("main.cpp", "src");
88+
exetarget.AddIncludeDir("include");
89+
exetarget.AddLibDep(statictarget);
90+
exetarget.Build();
91+
92+
// Build
93+
tf::Executor executor;
94+
tf::Taskflow taskflow;
95+
96+
// Explicitly setup your dependencies
97+
tf::Task statictargetTask = taskflow.composed_of(statictarget.GetTaskflow());
98+
tf::Task exetargetTask = taskflow.composed_of(exetarget.GetTaskflow());
99+
exetargetTask.succeed(statictargetTask);
100+
101+
// Run
102+
executor.run(taskflow);
103+
executor.wait_for_all();
104+
105+
DynamicLib
106+
-----------
107+
108+
Compile a dynamic library which is used by an executable
109+
110+
..code-block::cpp
111+
:linenos:
112+
:emphasize-lines: 7
113+
114+
// GCC specialized toolchain
115+
Toolchain_gcc toolchain;
116+
117+
// GCC specialized targets
118+
// Create "librandom.so" target (meant to use the GCC compiler)
119+
// On Windows the equivalent is the MinGW compiler
120+
DynamicTarget_gcc dynamictarget("librandom", gcc, "files");
121+
dynamictarget.AddSource("src/random.cpp");
122+
dynamictarget.AddHeader("include/random.h");
123+
dynamictarget.AddIncludeDir("include");
124+
dynamictarget.Build();
125+
126+
// GCC specialized targets
127+
// Create "dynamictest" target (meant to use the GCC compiler)
128+
// On Windows the equivalent is the MinGW compiler
129+
ExecutableTarget_gcc target("dynamictest", gcc, "files");
130+
target.AddSource("main.cpp", "src");
131+
target.AddIncludeDir("include");
132+
target.AddLibDep(dynamictarget);
133+
target.Build();
134+
135+
// Build
136+
tf::Executor executor;
137+
tf::Taskflow taskflow;
138+
139+
// Explicitly setup your dependencies
140+
auto dynamictargetTask = taskflow.composed_of(dynamictarget.GetTaskflow());
141+
auto targetTask = taskflow.composed_of(target.GetTaskflow());
142+
targetTask.succeed(dynamictargetTask);
143+
144+
executor.run(taskflow);
145+
executor.wait_for_all();
146+
147+
// Post Build step
148+
if (target.IsBuilt()) {
149+
fs::path copy_to_path =
150+
target.GetTargetBuildDir() / dynamictarget.GetTargetPath().filename();
151+
fs::copy(dynamictarget.GetTargetPath(), copy_to_path);
152+
}
153+
154+
..note::Our ``ExecutableTarget_gcc`` depends on ``DynamicTarget_gcc`` and requires the ``librandom.so`` file to be present in the same folder location as the executable when running.
155+
156+
Flags
157+
------
158+
159+
Using **PreprocessorFlags**, **C Compile flags**, **Cpp Compile flags** and **Link flags**
160+
161+
..code-block::cpp
162+
:linenos:
163+
:emphasize-lines: 12,13,14,15,23,24,25,26
164+
165+
// GCC specialized toolchain
166+
Toolchain_gcc toolchain;
167+
168+
// GCC specialized targets
169+
// Create "CppFlags" target (meant to use the GCC compiler)
170+
// On Windows the equivalent is the MinGW compiler
171+
ExecutableTarget_gcc cpptarget("CppFlags", gcc, "files");
172+
cpptarget.AddSource("main.cpp", "src");
173+
cpptarget.AddSource("src/random.cpp");
174+
cpptarget.AddHeader("include/random.h");
175+
cpptarget.AddIncludeDir("include");
176+
cpptarget.AddPreprocessorFlag("-DRANDOM=1");
177+
cpptarget.AddCppCompileFlag("-Wall");
178+
cpptarget.AddCppCompileFlag("-Werror");
179+
cpptarget.AddLinkFlag("-lm");
180+
cpptarget.Build();
181+
182+
// Gcc specialized targets
183+
// Create "CFlags" target (meant to use the GCC compiler)
184+
// On Windows the equivalent is the MinGW compiler
185+
ExecutableTarget_gcc ctarget("CFlags", gcc, "files");
186+
ctarget.AddSource("main.c", "src");
187+
ctarget.AddPreprocessorFlag("-DRANDOM=1");
188+
ctarget.AddCCompileFlag("-Wall");
189+
ctarget.AddCCompileFlag("-Werror");
190+
ctarget.AddLinkFlag("-lm");
191+
ctarget.Build();
192+
193+
// Build
194+
tf::Executor executor;
195+
tf::Taskflow taskflow;
196+
197+
// There isn't any dependency between the 2 targets
198+
taskflow.composed_of(cpptarget.GetTaskflow());
199+
taskflow.composed_of(ctarget.GetTaskflow());
200+
201+
executor.run(taskflow);
202+
executor.wait_for_all();
203+
204+
AfterInstall
205+
-------------
206+
207+
Use BuildCC with CMake
208+
209+
210+
* Install ``BuildCC`` via CMake to your system and add it to **PATH**
211+
* Use the script below to **compile** your build script to an executable
212+
* Copy the **Flags** build example
213+
* Run the executable from your project root directory
214+
215+
..code-block::cmake
216+
217+
# Package dependencies
218+
# fmt is imported by spdlog by default
219+
find_package(fmt_package NAMES "fmt" REQUIRED)
220+
find_package(spdlog_package NAMES "spdlog" REQUIRED)
221+
find_package(flatbuffers_header_only_package NAMES "flatbuffers_header_only" REQUIRED)
222+
find_package(taskflow_package NAMES "Taskflow" "taskflow" REQUIRED)
223+
find_package(CLI11_package NAMES "CLI11" REQUIRED)
224+
find_package(tiny_process_library_package NAMES "tiny-process-library" REQUIRED)
225+
226+
find_package(buildcc_package NAMES "buildcc" REQUIRED)
227+
228+
message("Find package: ${fmt_package_DIR}")
229+
message("Find package: ${spdlog_package_DIR}")
230+
message("Find package: ${flatbuffers_header_only_package_DIR}")
231+
message("Find package: ${taskflow_package_DIR}")
232+
message("Find package: ${CLI11_package_DIR}")
233+
message("Find package: ${tiny_process_library_package_DIR}") #
234+
235+
message("Find package: ${buildcc_package_DIR}")
236+
237+
# build executable
238+
add_executable(build build.cpp)
239+
target_include_directories(build PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
240+
target_link_libraries(build PRIVATE
241+
buildcc
242+
)
243+
if (${MINGW})
244+
message(WARNING "-Wl,--allow-multiple-definition for MINGW")
245+
target_link_options(build PRIVATE -Wl,--allow-multiple-definition)
246+
endif()
247+
248+
# Add your constants file for the environment
249+
configure_file(constants.h.in ${CMAKE_BINARY_DIR}/generated/constants.h @ONLY)
250+
251+
252+
Plugins
253+
--------
254+
255+
Demonstrating BuildCC supported plugin usage
256+
257+
* From the **Flags** example above
258+
* Add the targets for which you would like to generate the `Clang CompileCommands Database<https://clang.llvm.org/docs/JSONCompilationDatabase.html>`_
259+
260+
..code-block::cpp
261+
:linenos:
262+
263+
plugin::ClangCompileCommands({&cppflags, &cflags}).Generate();
264+
265+
PrecompileHeader
266+
----------------
267+
268+
TODO

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp