ソースを参照

Linking statically to C/C++ runtime for MS-Windows in all templates and SDK examples.
Statically linking on Linux won't work because it's a part of the system.

David Piuva 3 年 前
コミット
3b959e535d

+ 6 - 0
Source/SDK/cube/main.DsrProj

@@ -5,5 +5,11 @@ Crawl "main.cpp"
 Import "../../DFPSR/DFPSR.DsrHead"
 ProgramPath = "application"
 
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
+
 # Uncomment to enable debug mode, which is slower
 #Debug

+ 6 - 0
Source/SDK/fileFinder/main.DsrProj

@@ -3,6 +3,12 @@ CompilerFlag "-std=c++14"
 Crawl "main.cpp"
 ProgramPath = "application"
 
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
+
 # Uncomment to enable debug mode, which is slower
 #Debug
 

+ 6 - 0
Source/SDK/guiExample/main.DsrProj

@@ -5,5 +5,11 @@ Crawl "main.cpp"
 Import "../../DFPSR/DFPSR.DsrHead"
 ProgramPath = "application"
 
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
+
 # Uncomment to enable debug mode, which is slower
 #Debug

+ 6 - 0
Source/SDK/sandbox/main.DsrProj

@@ -13,5 +13,11 @@ Crawl "tool.cpp"
 Import "../../DFPSR/DFPSR.DsrHead"
 ProgramPath = "application"
 
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
+
 # Uncomment to enable debug mode, which is slower
 #Debug

+ 6 - 0
Source/SDK/terrain/main.DsrProj

@@ -5,5 +5,11 @@ Crawl "main.cpp"
 Import "../../DFPSR/DFPSR.DsrHead"
 ProgramPath = "application"
 
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
+
 # Uncomment to enable debug mode, which is slower
 #Debug

+ 6 - 0
Source/templates/basic3D/main.DsrProj

@@ -5,5 +5,11 @@ Crawl "main.cpp"
 Import "../../DFPSR/DFPSR.DsrHead"
 ProgramPath = "application"
 
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
+
 # Uncomment to enable debug mode, which is slower
 #Debug

+ 6 - 0
Source/templates/basicCLI/main.DsrProj

@@ -3,6 +3,12 @@ CompilerFlag "-std=c++14"
 Crawl "main.cpp"
 ProgramPath = "application"
 
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
+
 # Uncomment to enable debug mode, which is slower
 #Debug
 

+ 6 - 0
Source/templates/basicGUI/main.DsrProj

@@ -5,5 +5,11 @@ Crawl "main.cpp"
 Import "../../DFPSR/DFPSR.DsrHead"
 ProgramPath = "application"
 
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
+
 # Uncomment to enable debug mode, which is slower
 #Debug

+ 2 - 2
Source/tools/builder/buildProject.bat

@@ -1,6 +1,6 @@
 @echo off
 
-rem Using buildProject.sh
+rem Using buildProject.bat
 rem   %1 must be the *.DsrProj path, which is relative to the caller location.
 rem   %2... are variable assignments sent as input to the given project file.
 
rem   CPP_COMPILER_PATH should be modified if it does not already refer to an installed C++ compiler.
@@ -19,7 +19,7 @@ echo BUILDER_SOURCE = %BUILDER_SOURCE%
 
 set CPP_COMPILER_FOLDER=C:\Program\CodeBlocks\MinGW\bin
 set CPP_COMPILER_PATH=%CPP_COMPILER_FOLDER%\x86_64-w64-mingw32-g++.exe
-echo Change CPP_COMPILER_FOLDER and CPP_COMPILER_PATH in %BUILDER_FOLDER%\buildProject.sh if you are not using %CPP_COMPILER_PATH% as your compiler.
+echo Change CPP_COMPILER_FOLDER and CPP_COMPILER_PATH in %BUILDER_FOLDER%\buildProject.bat if you are not using %CPP_COMPILER_PATH% as your compiler.
 
 rem Check if the build system is compiled
 if exist %BUILDER_EXECUTABLE% (

+ 19 - 8
Source/tools/builder/generator.cpp

@@ -340,25 +340,36 @@ void generateCompilationScript(const Machine &settings, const ReadableString& pr
 	for (int i = 0; i < settings.compilerFlags.length(); i++) {
 		string_append(compilerFlags, " ", settings.compilerFlags[i]);
 	}
+	String linkerFlags;
+	for (int i = 0; i < settings.linkerFlags.length(); i++) {
+		string_append(linkerFlags, " -l", settings.linkerFlags[i]);
+	}
 	// TODO: Warn if -DNDEBUG, -DDEBUG, or optimization levels are given directly.
 	//       Using the variables instead is both more flexible by accepting input arguments
 	//       and keeping the same format to better reuse compiled objects.
-	ReadableString debugMode = getFlag(settings, U"Debug", U"0");
-	if (string_match(debugMode, U"0")) {
+	if (getFlagAsInteger(settings, U"Debug")) {
+		printText(U"Building with debug mode.\n");
+		string_append(compilerFlags, " -DDEBUG");
+	} else {
 		printText(U"Building with release mode.\n");
 		string_append(compilerFlags, " -DNDEBUG");
+	}
+	if (getFlagAsInteger(settings, U"StaticRuntime")) {
+		if (getFlagAsInteger(settings, U"Windows")) {
+			printText(U"Building with static runtime. Your application's binary will be bigger but can run without needing any installer.\n");
+			string_append(compilerFlags, " -static -static-libgcc -static-libstdc++");
+			string_append(linkerFlags, " -static -static-libgcc -static-libstdc++");
+		} else {
+			printText(U"The target platform does not support static linking of runtime! But don't worry about bundling any runtimes, because it comes with most of the Posix compliant operating systems.\n");
+		}
 	} else {
-		printText(U"Building with debug mode.\n");
-		string_append(compilerFlags, " -DDEBUG");
+		printText(U"Building with dynamic runtime. Don't forget to bundle the C and C++ runtimes with your application!\n");
 	}
 	ReadableString optimizationLevel = getFlag(settings, U"Optimization", U"2");
 		printText(U"Building with optimization level ", optimizationLevel, U".\n");
 	string_append(compilerFlags, " -O", optimizationLevel);
 
-	String linkerFlags;
-	for (int i = 0; i < settings.linkerFlags.length(); i++) {
-		string_append(linkerFlags, " -l", settings.linkerFlags[i]);
-	}
+
 
 	// Interpret ProgramPath relative to the project path.
 	ReadableString programPath = getFlag(settings, U"ProgramPath", language == ScriptLanguage::Batch ? U"program.exe" : U"program");

+ 3 - 1
Source/tools/builder/generator.h

@@ -19,11 +19,13 @@ void printDependencies();
 /*
 Setting variables:
 	* ScriptPath, a path to the script to be generated and saved. The extension of the filename decides which type of code to generate.
+	* ProgramPath, a path to the application to create.
 	* Compiler, a path or global alias to the compiler.
 	* CompileFrom, from which path should the compiler be executed? Leave empty to use the current directory.
 	* Debug, 0 for release, anything else (usually 1) for debug.
+	* StaticRuntime, 0 for dynamic runtime linking, anything else (usually 1) for static runtime.
 	* Optimization, a natural integer specifying the amount of optimization to apply.
-	* ProgramPath, a path to the application to create.
+	
 */
 void generateCompilationScript(const Machine &settings, const ReadableString& projectPath);
 

+ 0 - 6
Source/tools/builder/main.cpp

@@ -4,11 +4,6 @@
 //   Otherwise buildProject.sh will just see that an old version exists and use it.
 
 // TODO:
-//  * Let the build script define a temporary folder path for lazy compilation with reused *.o files.
-//    The /tmp folder is erased when shutting down the computer, which would force recompilation of each library after each time the computer has rebooted.
-//  * Find a way to check if a file is truly unique using a combination of pathless filenames, content checksums and visibility of surrounding files from the folder.
-//    This makes sure that including the same file twice using alternative ways of writing the path can be detected and trigger a warning.
-//    Can one convert the file ID from each platform into a string or 64-bit hash sum to quickly make sure that the file is unique?
 //  * Implement more features for the machine, such as:
 //    * Unary negation.
 //    * else and elseif cases.
@@ -19,7 +14,6 @@
 //    Pre-build can be used to generate and transpile code before compiling.
 //    Post-build should be used to execute the resulting program.
 //      Optionally with variables from the build script as input arguments.
-//  * Should the build system detect the local system automatically, or support cross compilation using a MinGW extension?
 
 #include "../../DFPSR/api/fileAPI.h"
 #include "generator.h"

+ 5 - 4
Source/tools/wizard/main.DsrProj

@@ -8,10 +8,11 @@ Import "../../DFPSR/DFPSR.DsrHead"
 # The DFPSR library uses C++14 as a minimum requirement, but you can use newer versions as well.
 CompilerFlag "-std=c++14"
 
-# Using static linking to avoid having to install standard libraries.
-CompilerFlag "-static"
-CompilerFlag "-static-libgcc"
-CompilerFlag "-static-libstdc++"
+# Linking statically to standard C/C++ libraries allow running the program without installing them.
+#   Recommended for making an installer for another application or programs that should not need an installer.
+# If you don't want static linking of standard C/C++ libraries, you have to comment out StaticRuntime
+#   and bundle the C/C++ runtime of the compiler with your program's installer.
+StaticRuntime
 
 # Find source code included by main recursively across header and implementation files with the same names.
 Crawl "main.cpp"