Skip to content

Commit cd69ea2

Browse files
Merge pull request #39 from Neko-Box-Coder/BuildTypes
Supporting Build types
2 parents c38db72 + 555733b commit cd69ea2

28 files changed

+935
-153
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ add_library(runcpp2 STATIC
137137
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/StageInfo.cpp"
138138
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ProfilesDefines.cpp"
139139
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/FilesToCopyInfo.cpp"
140+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/BuildTypeHelper.cpp"
140141
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/ProfileHelper.cpp"
141142
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/CompilingLinking.cpp"
142143
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/ConfigParsing.cpp"

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
1-
# NOTE: All command substitutions are passed directly to the shell.
2-
# Be cautious when using user-provided input in your build commands to avoid potential security risks.
3-
4-
# NOTE: All the options here are defaulted to empty.
5-
# You can uncomment different sections to set what you want.
6-
7-
# (Optional) Whether to pass the script path as the second parameter when running
1+
# This is the template for specifying build settings.
2+
# Many of the settings are passed directly to the shell.
3+
# Be cautious when using user-provided input in your build commands to avoid potential security risks.
4+
# Output from commands such as Setup or Cleanup won't be shown unless log level is set to info.
5+
# If the default is not mentioned for a setting, it will be empty.
6+
7+
# Each of the platform dependent settings can be listed under
8+
# - DefaultPlatform
9+
# - Windows
10+
# - Linux
11+
# - MacOS
12+
# - Unix
13+
14+
# You can find all the profiles in your config folder.
15+
# This can be found by running `runcpp2 --show-config-path`.
16+
# Specifying "DefaultProfile" in the profile name will allow any profiles
17+
# and use the user's preferred one.
18+
19+
# (Optional) Whether to pass the script path as the second parameter when running. Default is false
820
PassScriptPath: false
921

10-
# # (Optional) Language of the script
22+
# (Optional) Language of the script. Default is determined by file extension
1123
Language: "c++"
1224

13-
# (Optional) Preferred profiles for the script for each platform.
14-
# Profiles are listed in user config file,
15-
# which can be retreived by running `runcpp2 --show-config-path`
16-
# Each of the platform dependent settings can be listed under
17-
# - Default
18-
# - Windows
19-
# - Linux
20-
# - MacOS
21-
# - Unix
25+
# (Optional) The type of output to build. Default is Executable
26+
# Supported types:
27+
# - Executable: Build as executable that can be run
28+
# - Static: Build as static library (.lib/.a)
29+
# - Shared: Build as shared library (.dll/.so)
30+
# - Objects: Only compile to object files without linking
31+
BuildType: Executable
32+
33+
# TODO: Rename this
34+
# (Optional) Allowed profiles for the script for each platform.
35+
# Any profiles will be used if none is specified for the platform.
2236
RequiredProfiles:
2337
Windows: ["g++"]
2438
Linux: ["g++"]
@@ -28,7 +42,7 @@ RequiredProfiles:
2842
OverrideCompileFlags:
2943
# Target Platform
3044
DefaultPlatform:
31-
# Profile with the respective flags to override. ("DefaultProfile" for any profile)
45+
# Profile with the respective flags to override
3246
"g++":
3347
# (Optional) Flags to be removed from the default compile flags, separated by space
3448
Remove: ""
@@ -40,7 +54,7 @@ OverrideCompileFlags:
4054
OverrideLinkFlags:
4155
# Target Platform
4256
DefaultPlatform:
43-
# Profile with the respective flags to override ("DefaultProfile" for any profile)
57+
# Profile with the respective flags to override
4458
"g++":
4559
# (Optional) Flags to be removed from the default link flags, separated by space
4660
Remove: ""
@@ -59,35 +73,35 @@ OtherFilesToBeCompiled:
5973

6074
# (Optional) Include paths (relative to script file path) for each platform and profile
6175
IncludePaths:
62-
# Target Platform (DefaultPlatform, Windows, Linux, MacOS, or Unix)
76+
# Target Platform
6377
DefaultPlatform:
64-
# Target Profile (e.g., "g++", "clang++", "msvc", or "DefaultProfile" for any profile)
78+
# Target Profile
6579
DefaultProfile:
6680
- "./include"
6781
- "./src/include"
6882

6983
# (Optional) Define cross-compiler defines for each platform and profile.
70-
# Defines can be specified as just a name or as a name-value pair.
84+
# Defines can be specified as just a name or as a name-value pair.
7185
Defines:
72-
# Target Platform (DefaultPlatform, Windows, Linux, MacOS, or Unix)
86+
# Target Platform
7387
DefaultPlatform:
74-
# Profile name (e.g., "g++", "clang++", "msvc", or "DefaultProfile" for any profile)
88+
# Profile name
7589
DefaultProfile:
7690
- "EXAMPLE_DEFINE" # Define without a value
7791
- "VERSION_MAJOR=1" # Define with a value
7892

7993
# (Optional) Setup commands are run once before the script is first built.
80-
# These commands are run at the script's location when no build directory exists.
94+
# These commands are run at the script's location when no build directory exists.
8195
Setup:
82-
# Target Platform (DefaultPlatform, Windows, Linux, MacOS, or Unix)
96+
# Target Platform
8397
DefaultPlatform:
84-
# Profile name (e.g., "g++", "clang++", "msvc", or "DefaultProfile" for any profile)
98+
# Profile name
8599
DefaultProfile:
86100
# List of setup commands
87101
- "echo Setting up script..."
88102

89103
# (Optional) PreBuild commands are run before each build.
90-
# These commands are run in the build directory before compilation starts.
104+
# These commands are run in the build directory before compilation starts.
91105
PreBuild:
92106
# Target Platform
93107
DefaultPlatform:
@@ -96,7 +110,7 @@ PreBuild:
96110
- "echo Starting build..."
97111

98112
# (Optional) PostBuild commands are run after each successful build.
99-
# These commands are run in the output directory where binaries are located.
113+
# These commands are run in the output directory where binaries are located.
100114
PostBuild:
101115
# Target Platform
102116
DefaultPlatform:
@@ -105,7 +119,7 @@ PostBuild:
105119
- "echo Build completed..."
106120

107121
# (Optional) Cleanup commands are run when using the --cleanup option.
108-
# These commands are run at the script's location before the build directory is removed.
122+
# These commands are run at the script's location before the build directory is removed.
109123
Cleanup:
110124
# Target Platform
111125
DefaultPlatform:
@@ -121,23 +135,26 @@ Dependencies:
121135
# Supported platforms of the dependency
122136
Platforms: [Windows, Linux, MacOS]
123137

124-
# The source of getting the dependency (Git, Local)
138+
# Where to get and copy the dependency (Git, Local)
139+
# Either Git or Local can exist, not both
125140
Source:
126-
# (Optional) Import dependency configuration from a YAML file
127-
# For Git source: Path is relative to the git repository root
128-
# For Local source: Path is relative to the script directory.
129-
# If neither source exists, local source with root script directory is assumed.
130-
# ImportPath: "config/dependency.yaml"
141+
# (Optional) Import dependency configuration from a YAML file if this field exists
142+
# All other fields (Name, Platforms, etc...) are not needed if this field exists
143+
# For Git source: Path is relative to the git repository root
144+
# For Local source: Path is relative to the script directory.
145+
# If neither source exists, local source with root script directory is assumed.
146+
ImportPath: "config/dependency.yaml"
131147

132-
# Git: Dependency or import YAML file exists in a git server, and needs to be cloned.
148+
# Dependency or import YAML file exists in a git server, and needs to be cloned to build directory
133149
Git:
134150
# Git repository URL
135151
URL: "https://github.com/MyUser/MyLibrary.git"
136152

137-
# Local: Dependency or import YAML file exists in local filesystem
138-
# Local:
139-
# # Path to the library directory
140-
# Path: "./libs/LocalLibrary"
153+
# Dependency or import YAML file exists in local filesystem directory,
154+
# and needs to be copied to build directory
155+
Local:
156+
# Path to the library directory
157+
Path: "./libs/LocalLibrary"
141158

142159

143160
# Library Type (Static, Object, Shared, Header)
@@ -158,7 +175,7 @@ Dependencies:
158175
SearchLibraryNames: ["MyLibrary"]
159176

160177
# (Optional) The library names to be excluded from being searched.
161-
# Works the same as SearchLibraryNames but will NOT be linked instead
178+
# Works the same as SearchLibraryNames but will NOT be linked instead
162179
ExcludeLibraryNames: []
163180

164181
# The path (relative to the dependency folder) to be searched for the dependency binaries
@@ -182,23 +199,25 @@ Dependencies:
182199
Build:
183200
# Target Platform
184201
DefaultPlatform:
185-
# Target Profile ("DefaultProfile" for any profile)
202+
# Target Profile
186203
"g++":
187204
- "cd build && cmake .."
188205
- "cd build && cmake --build ."
189206

190207
# (Optional) Cleanup commands are run when the reset option is present. Normally nothing needs
191208
# to be done since the dependency folder will be removed automatically.
192209
Cleanup:
210+
# Target Platform
193211
Linux:
212+
# Target Profile
194213
"g++":
195214
- "sudo apt purge MyLibrary"
196215

197216
# (Optional) Files to be copied to next to output binary for each platform and profile
198217
FilesToCopy:
199-
# Target Platform (DefaultPlatform, Windows, Linux, MacOS, or Unix)
218+
# Target Platform
200219
DefaultPlatform:
201-
# Profile name (e.g., "g++", "clang++", "msvc", or "DefaultProfile" for any profile)
220+
# Profile name
202221
DefaultProfile:
203222
# List of files to copy (relative to the dependency folder)
204223
- "assets/textures/sprite.png"

DefaultYAMLs/DefaultUserConfig.yaml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ Profiles:
172172
# (Optional) The commands to run in **shell** AFTER compiling
173173
# This is run inside the .runcpp2 directory where the build happens.
174174
# Cleanup: []
175+
ExecutableShared:
176+
DefaultPlatform:
177+
Flags: "-std=c++17 -Wall -g -fpic"
178+
Executable: "g++"
179+
RunParts: *g++_CompileRunParts
180+
# Setup: []
181+
# Cleanup: []
175182
Static:
176183
DefaultPlatform:
177184
Flags: "-std=c++17 -Wall -g"
@@ -227,14 +234,15 @@ Profiles:
227234
# {OutputFilePath}: (Similar to previous)
228235
LinkTypes:
229236
Executable:
230-
Unix:
237+
DefaultPlatform:
231238
Flags: "-Wl,-rpath,\\$ORIGIN"
232239
Executable: "g++"
233240
RunParts: *g++_LinkRunParts
234241
# Setup: []
235242
# Cleanup: []
236-
Windows:
237-
Flags: "-Wl,-rpath,\\$ORIGIN"
243+
ExecutableShared:
244+
DefaultPlatform:
245+
Flags: "-shared -Wl,-rpath,\\$ORIGIN"
238246
Executable: "g++"
239247
RunParts: *g++_LinkRunParts
240248
# Setup: []
@@ -247,13 +255,7 @@ Profiles:
247255
# Setup: []
248256
# Cleanup: []
249257
Shared:
250-
Unix:
251-
Flags: "-shared -Wl,-rpath,\\$ORIGIN"
252-
Executable: "g++"
253-
RunParts: *g++_LinkRunParts
254-
# Setup: []
255-
# Cleanup: []
256-
Windows:
258+
DefaultPlatform:
257259
Flags: "-shared -Wl,-rpath,\\$ORIGIN"
258260
Executable: "g++"
259261
RunParts: *g++_LinkRunParts
@@ -286,6 +288,11 @@ Profiles:
286288
<<: *MSVC_CompileFlags
287289
Executable: "CL.exe"
288290
RunParts: *vs2022_v17+_CompileRunParts
291+
ExecutableShared:
292+
Windows:
293+
<<: *MSVC_CompileFlags
294+
Executable: "CL.exe"
295+
RunParts: *vs2022_v17+_CompileRunParts
289296
Static:
290297
Windows:
291298
<<: *MSVC_CompileFlags
@@ -296,7 +303,6 @@ Profiles:
296303
<<: *MSVC_CompileFlags
297304
Executable: "CL.exe"
298305
RunParts: *vs2022_v17+_CompileRunParts
299-
# Specify the linker settings
300306
Linker:
301307
PreRun:
302308
Windows: ".\\prerun.bat"
@@ -310,12 +316,7 @@ Profiles:
310316
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /manifest:embed /SUBSYSTEM:CONSOLE
311317
Executable: "link.exe"
312318
RunParts: *vs2022_v17+_LinkRunParts
313-
Static:
314-
Windows:
315-
Flags: "/NOLOGO"
316-
Executable: "lib.exe"
317-
RunParts: *vs2022_v17+_LinkRunParts
318-
Shared:
319+
ExecutableShared:
319320
Windows:
320321
Flags: >-
321322
/NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib
@@ -329,3 +330,17 @@ Profiles:
329330
CommandPart: " \"{LinkFilePath}\""
330331
Setup: [ "echo EXPORTS > .\\temp.def", "echo. main @1 >> .\\temp.def" ]
331332
Cleanup: [ "del .\\temp.def" ]
333+
Static:
334+
Windows:
335+
Flags: "/NOLOGO"
336+
Executable: "lib.exe"
337+
RunParts: *vs2022_v17+_LinkRunParts
338+
Shared:
339+
Windows:
340+
Flags: >-
341+
/NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib
342+
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /manifest:embed /SUBSYSTEM:CONSOLE
343+
/DLL
344+
Executable: "link.exe"
345+
RunParts: *vs2022_v17+_LinkRunParts
346+

0 commit comments

Comments
 (0)