Skip to content

Commit b145fc0

Browse files
Initial implementation for build type support
1 parent c38db72 commit b145fc0

21 files changed

+460
-93
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"

Include/runcpp2/Data/BuildType.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef RUNCPP2_DATA_BUILD_TYPE_HPP
2+
#define RUNCPP2_DATA_BUILD_TYPE_HPP
3+
4+
#include <string>
5+
6+
namespace runcpp2
7+
{
8+
namespace Data
9+
{
10+
enum class BuildType
11+
{
12+
EXECUTABLE,
13+
STATIC,
14+
SHARED,
15+
OBJECTS,
16+
COUNT
17+
};
18+
19+
inline std::string BuildTypeToString(BuildType buildType)
20+
{
21+
static_assert(static_cast<int>(BuildType::COUNT) == 4, "Add new type to be processed");
22+
23+
switch(buildType)
24+
{
25+
case BuildType::EXECUTABLE:
26+
return "Executable";
27+
28+
case BuildType::STATIC:
29+
return "Static";
30+
31+
case BuildType::SHARED:
32+
return "Shared";
33+
34+
case BuildType::OBJECTS:
35+
return "Objects";
36+
37+
default:
38+
return "";
39+
}
40+
}
41+
42+
inline BuildType StringToBuildType(const std::string& buildTypeStr)
43+
{
44+
if(buildTypeStr == "Executable")
45+
return BuildType::EXECUTABLE;
46+
else if(buildTypeStr == "Static")
47+
return BuildType::STATIC;
48+
else if(buildTypeStr == "Shared")
49+
return BuildType::SHARED;
50+
else if(buildTypeStr == "Objects")
51+
return BuildType::OBJECTS;
52+
53+
return BuildType::COUNT;
54+
}
55+
}
56+
}
57+
58+
#endif
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef RUNCPP2_DATA_BUILD_TYPE_HELPER_HPP
2+
#define RUNCPP2_DATA_BUILD_TYPE_HELPER_HPP
3+
4+
#include "runcpp2/Data/BuildType.hpp"
5+
#include "runcpp2/Data/FilesTypesInfo.hpp"
6+
#include "runcpp2/Data/Profile.hpp"
7+
#include "ghc/filesystem.hpp"
8+
9+
namespace runcpp2
10+
{
11+
namespace Data
12+
{
13+
namespace BuildTypeHelper
14+
{
15+
const FileProperties* GetOutputFileProperties( const FilesTypesInfo& filesTypes,
16+
BuildType buildType,
17+
bool asExecutable);
18+
19+
bool NeedsLinking(BuildType buildType);
20+
21+
bool GetOutputPath( const ghc::filesystem::path& buildDir,
22+
const std::string& scriptName,
23+
const Profile& profile,
24+
BuildType buildType,
25+
bool asExecutable,
26+
ghc::filesystem::path& outPath);
27+
}
28+
}
29+
}
30+
31+
#endif

Include/runcpp2/Data/ScriptInfo.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "runcpp2/Data/ProfilesProcessPaths.hpp"
88
#include "runcpp2/Data/ProfilesDefines.hpp"
99
#include "runcpp2/Data/ProfilesCommands.hpp"
10+
#include "runcpp2/Data/BuildType.hpp"
1011

1112
#if !defined(NOMINMAX)
1213
#define NOMINMAX 1
@@ -27,6 +28,7 @@ namespace runcpp2
2728
public:
2829
std::string Language;
2930
bool PassScriptPath = false;
31+
BuildType CurrentBuildType = BuildType::EXECUTABLE;
3032
std::unordered_map<PlatformName, std::vector<ProfileName>> RequiredProfiles;
3133

3234
std::unordered_map<PlatformName, ProfilesFlagsOverride> OverrideCompileFlags;

Include/runcpp2/Data/StageInfo.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RUNCPP2_DATA_STAGE_INFO_HPP
33

44
#include "runcpp2/Data/ParseCommon.hpp"
5+
#include "runcpp2/Data/BuildType.hpp"
56
#include "runcpp2/YamlLib.hpp"
67

78
#include <vector>
@@ -55,6 +56,7 @@ namespace runcpp2
5556

5657
bool ConstructCommand( const SubstitutionMap& substitutionMap,
5758
bool isExecutable,
59+
BuildType buildType,
5860
std::string& outCommand) const;
5961

6062
bool ParseYAML_Node(ryml::ConstNodeRef& node, std::string outputTypeKeyName);

Include/runcpp2/PipelineSteps.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ namespace runcpp2
113113
const std::string& scriptName,
114114
const Data::Profile& profile,
115115
const std::unordered_map<CmdOptions, std::string>& currentOptions,
116+
const Data::ScriptInfo& scriptInfo,
116117
ghc::filesystem::path& outTarget);
117118

118119
bool GatherSourceFiles( const ghc::filesystem::path& absoluteScriptPath,

Src/Tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ create_data_test(FilesTypesInfoTest)
3535
create_data_test(ProfilesFlagsOverrideTest)
3636
create_data_test(StageInfoTest)
3737
create_data_test(DependencyInfoTest)
38+
create_data_test(BuildTypeTest)
3839
create_data_test(ScriptInfoTest)
3940
create_data_test(ProfileTest)
4041

0 commit comments

Comments
 (0)