Skip to content

Commit e10b25f

Browse files
Merge pull request #3 from Neko-Box-Coder/DynamicLib
Using dynamic library instead of compiling executable
2 parents 973f8f8 + a481126 commit e10b25f

34 files changed

+1679
-755
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
[submodule "rapidyaml"]
1717
path = External/rapidyaml
1818
url = https://github.com/biojppm/rapidyaml.git
19+
[submodule "dylib"]
20+
path = External/dylib
21+
url = https://github.com/martin-olivier/dylib.git

CMakeLists.txt

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ set(CMAKE_CXX_STANDARD 11)
99

1010
option(RUNCPP2_UPDATE_DEFAULT_YAMLS "Update default yaml files" OFF)
1111

12-
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/ssLogger")
13-
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/rapidyaml")
14-
1512
# =========================================================================
16-
# filesystem
13+
# External Dependencies
1714
# =========================================================================
15+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/ssLogger")
16+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/rapidyaml")
1817
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/filesystem")
18+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/System2")
19+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/dylib")
20+
21+
# Copy cfgpath.h
22+
configure_file( "${CMAKE_CURRENT_LIST_DIR}/External/cfgpath/cfgpath.h"
23+
"${CMAKE_CURRENT_LIST_DIR}/Include/cfgpath.h" COPYONLY)
24+
1925

2026
# =========================================================================
2127
# Generate yaml files as c
@@ -50,38 +56,22 @@ if(RUNCPP2_UPDATE_DEFAULT_YAMLS OR EMBEDDED_FILE_SIZE LESS 1024)
5056
endif()
5157
endif()
5258

53-
54-
# =========================================================================
55-
# System2
56-
# =========================================================================
57-
58-
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/System2")
59-
60-
# =========================================================================
61-
# cfgpath
62-
# =========================================================================
63-
64-
# Copy cfgpath.h
65-
configure_file( "${CMAKE_CURRENT_LIST_DIR}/External/cfgpath/cfgpath.h"
66-
"${CMAKE_CURRENT_LIST_DIR}/Include/cfgpath.h" COPYONLY)
67-
68-
69-
7059
# =========================================================================
7160
# runcpp2
7261
# =========================================================================
7362

7463
add_executable(runcpp2 "${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/CompilerInfo.cpp"
75-
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/CompilerProfile.cpp"
64+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/Profile.cpp"
7665
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencyInfo.cpp"
7766
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencyLinkProperty.cpp"
7867
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencySetup.cpp"
7968
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencySource.cpp"
69+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/FileProperties.cpp"
8070
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/FlagsOverrideInfo.cpp"
8171
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ProfilesFlagsOverride.cpp"
8272
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/LinkerInfo.cpp"
8373
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ScriptInfo.cpp"
84-
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/CompilerProfileHelper.cpp"
74+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/ProfileHelper.cpp"
8575
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/CompilingLinking.cpp"
8676
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/ConfigParsing.cpp"
8777
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/DefaultYAMLs.c"
@@ -95,7 +85,7 @@ add_executable(runcpp2 "${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/CompilerInfo
9585

9686
target_include_directories(runcpp2 PRIVATE "${CMAKE_CURRENT_LIST_DIR}/Include")
9787

98-
target_link_libraries(runcpp2 PRIVATE ssLogger ghc_filesystem System2 ryml::ryml)
88+
target_link_libraries(runcpp2 PRIVATE ssLogger ghc_filesystem System2 ryml::ryml dylib)
9989

10090
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
10191
set(STANDARD_COMPILE_FLAGS "/utf-8;/W1")

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,40 @@
44
# (Optional) Language of the script
55
Language: "c++"
66

7-
# (Optional) Preferred compiler/linker profiles for the script
7+
# Each of the platform dependent settings can be listed under
8+
# - All
9+
# - Windows
10+
# - Linux
11+
# - MacOS
12+
# - Unix
13+
14+
# (Optional) Preferred compiler/linker profiles for the script for each platform
815
RequiredProfiles:
916
Windows: ["g++"]
1017
Linux: ["g++"]
1118
MacOS: ["g++"]
1219

13-
# (Optional) Override the default compile flags
20+
# (Optional) Override the default compile flags for each platform
1421
OverrideCompileFlags:
15-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
1622
All:
1723
# Profile with the respective flags to override
1824
"g++":
19-
# Flags to be removed from the default compile flags, separated by space
25+
# (Optional) Flags to be removed from the default compile flags, separated by space
2026
Remove: ""
2127

22-
# Additional flags to be appended to the default compile flags, separated by space
28+
# (Optional) Additional flags to be appended to the default compile flags, separated by space
2329
Append: ""
2430

2531

26-
# (Optional) Override the default link flags
32+
# (Optional) Override the default link flags for each platform
2733
OverrideLinkFlags:
28-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
2934
All:
3035
# Profile with the respective flags to override
3136
"g++":
32-
# Flags to be removed from the default link flags, separated by space
37+
# (Optional) Flags to be removed from the default link flags, separated by space
3338
Remove: ""
3439

35-
# Additional flags to be appended to the default link flags, separated by space
40+
# (Optional) Additional flags to be appended to the default link flags, separated by space
3641
Append: ""
3742

3843
# (Optional) The list of dependencies needed by the script
@@ -43,7 +48,7 @@ Dependencies:
4348
# Supported platforms of the dependency
4449
Platforms: [Windows, Linux, MacOS]
4550

46-
# The source of getting the dependency
51+
# The source of getting the dependency (Git, Local)
4752
Source:
4853
Type: Git
4954
Value: "https://github.com/MyUser/MyLibrary.git"
@@ -68,17 +73,15 @@ Dependencies:
6873
# The path (relative to the dependency folder) to be searched for the dependency binaries
6974
SearchDirectories: ["./build"]
7075

71-
# (Optional) Additional link options for this dependency
76+
# (Optional) Additional link options for this dependency for each platform
7277
AdditionalLinkOptions:
73-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
7478
All: []
7579

7680

77-
# (Optional) List of setup commands for the supported platforms
81+
# (Optional) List of setup commands for each platform
7882
Setup:
79-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
8083
All:
81-
# Setup commands for the specified profile.
84+
# Setup shell commands for the specified profile.
8285
# All commands are run in the dependency folder
8386
"g++":
8487
- "mkdir build"
Lines changed: 108 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# yaml-language-server: $schema=./UserConfigSchema.json
22

33
---
4-
# A default compiler profile to be used if not specified while running the build script
4+
# A profile to be used if not specified while running the build script
55
PreferredProfile: "g++"
66

77
# List of compiler/linker profiles that instruct how to compile/link
8-
CompilerProfiles:
8+
Profiles:
99
- Name: "g++"
1010

1111
# The file extensions associated with the profile
@@ -16,111 +16,151 @@ CompilerProfiles:
1616

1717
# (Optional) Steps to run before calling the compiler/linker.
1818
# This is run inside the .runcpp2 directory where the build happens.
19-
SetupSteps:
20-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
21-
All: []
19+
# SetupSteps:
20+
# # Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
21+
# All: []
2222

23-
# The file extension for the object files for each platform
24-
ObjectFileExtensions:
25-
Windows: obj
26-
Unix: o
23+
# The following fields set the prefixes and extensions for each type of the files
24+
# If the name of an object files are libtest.so and libtest2.so,
25+
# the prefixes and extensions are "lib" and ".so"
2726

28-
# The file extensions for the shared libraries for each platform
29-
SharedLibraryExtensions:
30-
Windows: [dll, lib]
31-
Linux: [so]
32-
MacOS: [dylib]
27+
# Each of the platform dependent settings can be listed under
28+
# - All
29+
# - Windows
30+
# - Linux
31+
# - MacOS
32+
# - Unix
3333

34-
# The file extensions for the static libraries for each platform
35-
StaticLibraryExtensions:
36-
Windows: [lib]
37-
Unix: [a]
34+
# The file properties for the object files for each platform.
35+
ObjectLinkFile:
36+
Prefix:
37+
All: ""
38+
Extension:
39+
Windows: ".obj"
40+
Unix: ".o"
41+
42+
# The file properties for the files to be **linked** as shared libraries for each platform
43+
SharedLinkFile:
44+
Prefix:
45+
Windows: ""
46+
Linux: "lib"
47+
MacOS: ""
48+
Extension:
49+
Windows: ".lib"
50+
Linux: ".so"
51+
MacOS: ".dylib"
52+
53+
# The file properties for the files to be **copied** as shared libraries for each platform
54+
SharedLibraryFile:
55+
Prefix:
56+
Windows: ""
57+
Linux: "lib"
58+
MacOS: ""
59+
Extension:
60+
Windows: ".dll"
61+
Linux: ".so"
62+
MacOS: ".dylib"
3863

39-
# (Optional) The file extensions for debug symbols to be copied alongside the binary
40-
DebugSymbolFileExtensions:
41-
Windows: []
42-
Unix: []
64+
# The file properties for the files to be linked as static libraries for each platform
65+
StaticLinkFile:
66+
Prefix:
67+
Unix: "lib"
68+
Windows: ""
69+
Extension:
70+
Windows: ".lib"
71+
Unix: ".a"
4372

44-
# Specify the compiler settings, so the final flow will be:
45-
# [Setup steps if any] --> {Executable} {CompileArgs}
73+
# (Optional) The file properties for debug symbols to be copied alongside the binary
74+
# for each platform
75+
# DebugSymbolFile:
76+
# Prefix:
77+
# Windows: ""
78+
# Unix: ""
79+
# Extension:
80+
# Windows: ""
81+
# Unix: ""
82+
83+
# Specify the compiler settings
4684
Compiler:
4785
# (Optional) The command to run together before running each compile command
48-
EnvironmentSetup:
49-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
50-
All: ""
86+
# in **shell** for each platform
87+
# EnvironmentSetup:
88+
# All: ""
5189

5290
# Executable to be called
5391
Executable: "g++"
5492

55-
# Default arguments to provide for compilation which can be overridden by the script
93+
# Default arguments to provide for compilation which can be overridden
94+
# by the script for each platform
5695
DefaultCompileFlags:
57-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
5896
All: "-std=c++17 -Wall -Werror"
5997

60-
# Flags for compiling to an executable
98+
# Flags for compiling to an executable for each platform
6199
ExecutableCompileFlags:
62-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
63100
All: ""
64101

65-
# Flags for compiling to a static library
102+
# Flags for compiling to a static library for each platform
66103
StaticLibCompileFlags:
67-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
68104
All: ""
69105

70-
# Flags for compiling to a shared library
106+
# Flags for compiling to a shared library for each platform
71107
SharedLibCompileFlags:
72-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
73-
All: ""
108+
All: "-fpic"
74109

75-
# The syntax to compile the given file.
76-
# [Setup steps if any] -->
77-
# {Executable} {CompilePart} {IncludePart}...(for each dependency) {InputPart} {OutputPart}
78-
# {CompileFlags}, {IncludePath}, {InputFile}, {ObjectFile} will be replaced accordingly
110+
# The compile syntax in shell for a given file:
111+
# {Executable} {CompilePart} [ {IncludePart}...(for each dependency) ]
112+
# {InputPart} {OutputPart}
79113
CompileArgs:
114+
# {CompileFlags} will be replaced by *CompileFlags set above depending on what
115+
# we are compiling
80116
CompilePart: "-c {CompileFlags}"
81-
IncludePart: "-I{IncludePath}"
82-
InputPart: "{InputFile}"
83-
OutputPart: "-o {ObjectFile}"
117+
118+
# {IncludeDirectoryPath} will be replaced by the IncludePaths set by the dependencies
119+
IncludePart: "-I{IncludeDirectoryPath}"
120+
121+
# {InputFilePath} will be replaced by the path to the script we are trying to compile
122+
InputPart: "{InputFilePath}"
123+
124+
# {ObjectFilePath} will be replaced by the path to the output object file
125+
OutputPart: "-o {ObjectFilePath}"
84126

85-
# Specify the linker settings, so the final flow will be:
86-
# [Setup steps if any] --> {Executable} {OutputPart} {DependenciesPart}...(for each dependency)
127+
# Specify the linker settings
87128
Linker:
88-
# (Optional) The command to run together before running each link command
89-
EnvironmentSetup:
90-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
91-
All: ""
129+
# (Optional) The command to run together before running each link command
130+
# in **shell** for each platform
131+
# EnvironmentSetup:
132+
# All: ""
92133

93134
# Executable to be called
94135
Executable: "g++"
95136

96137
# Default arguments to provide for linking dependencies to the binary,
97-
# which can be overridden by the script
138+
# which can be overridden by the script for each platform
98139
DefaultLinkFlags:
99-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
100140
All: ""
101141

102-
# Flags for linking as an executable
142+
# Flags for linking as an executable for each platform
103143
ExecutableLinkFlags:
104-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
105-
All: ""
144+
All: "-Wl,-rpath,\\$ORIGIN"
106145

107-
# Flags for linking as a static library
146+
# Flags for linking as a static library for each platform
108147
StaticLibLinkFlags:
109-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
110148
All: ""
111149

112-
# Flags for linking as a shared library
150+
# Flags for linking as a shared library for each platform
113151
SharedLibLinkFlags:
114-
# Applies to all platforms (Can be changed to Linux, MacOS, Windows, Unix, etc.)
115-
All: ""
152+
Unix: "-shared -Wl,-rpath,\\$ORIGIN"
153+
Windows: "-shared -Wl,-rpath,$ORIGIN"
116154

117-
# The syntax to link the given file
118-
LinkerArgs:
119-
# Syntax for outputting to the binary.
120-
# {LinkFlags}, {OutputFile}, {ObjectFile} will be replaced accordingly
121-
OutputPart: "{LinkFlags} -o {OutputFile} {ObjectFile}"
155+
# The link syntax in shell for a given file:
156+
# {OutputPart} {LinkPart}...(for script object file and each dependencies if any)
157+
LinkArgs:
158+
# {LinkFlags} will be replaced by *LinkFlags set above depending on what
159+
# we are linking to
160+
#
161+
# {OutputFilePath} will be replaced by the path to the output file
162+
OutputPart: "{LinkFlags} -o {OutputFilePath}"
122163

123-
# Syntax for linking each dependency.
124-
# {DependencyFile} will be replaced accordingly
125-
#DependenciesPart: "-l:{DependencyFile}"
126-
DependenciesPart: "{DependencyFile}"
164+
# {LinkFilePath} will be replaced by the path to the object file
165+
# we are linking against
166+
LinkPart: "{LinkFilePath}"

0 commit comments

Comments
 (0)