diff --git a/premake4.lua b/premake4.lua index 561bad8ac..5a68a39cc 100644 --- a/premake4.lua +++ b/premake4.lua @@ -160,6 +160,7 @@ newoption { trigger = "with-gles1", description = "Compile with GLES1 support" } newoption { trigger = "with-mojoal", description = "Compile with mojoAL as OpenAL implementation instead of using openal-soft (requires SDL2 backend)" } newoption { trigger = "use-frameworks", description = "In macOS it will try to link the external libraries from its frameworks. For example, instead of linking against SDL2 it will link agains SDL2.framework." } newoption { trigger = "with-emscripten-pthreads", description = "Enables emscripten build to use posix threads" } +newoption { trigger = "with-mold-linker", description = "Tries to use the mold linker instead of the default linker of the toolchain" } newoption { trigger = "with-backend", description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.", @@ -387,6 +388,29 @@ function fix_shared_lib_linking_path( package_name, libname ) end end +function version_to_number( version ) + versionpart = 0 + versionnum = 0 + versionmod = 1000 + for str in string.gmatch(version, "[^%.]+") do + versionnum = versionnum + tonumber(str) * versionmod + versionpart = versionpart + 1 + if versionpart == 1 then + versionmod = 100 + elseif versionpart == 2 then + versionmod = 10 + end + end + return versionnum +end + +function popen( executable_path ) + local handle = io.popen(executable_path) + local result = handle:read("*a") + handle:close() + return result +end + function build_link_configuration( package_name, use_ee_icon ) includedirs { "include" } @@ -444,6 +468,20 @@ function build_link_configuration( package_name, use_ee_icon ) end end + if _OPTIONS["with-mold-linker"] then + if _OPTIONS.platform == "clang" or _OPTIONS.platform == "clang-analyzer" then + linkoptions { "-fuse-ld=mold" } + else + gccversion = popen( "gcc -dumpfullversion" ) + gccversionnumber = version_to_number( gccversion ) + if gccversionnumber >= 12110 then + linkoptions { "-fuse-ld=mold" } + else + linkoptions { "-B/usr/bin/mold" } + end + end + end + configuration "debug" defines { "DEBUG", "EE_DEBUG", "EE_MEMORY_MANAGER" } flags { "Symbols" } diff --git a/premake5.lua b/premake5.lua index 8c3bab1eb..9e033720a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -8,6 +8,7 @@ newoption { trigger = "with-mojoal", description = "Compile with mojoAL as OpenA newoption { trigger = "use-frameworks", description = "In macOS it will try to link the external libraries from its frameworks. For example, instead of linking against SDL2 it will link against SDL2.framework." } newoption { trigger = "windows-vc-build", description = "This is used to build the framework in Visual Studio downloading its external dependencies and making them available to the VS project without having to install them manually." } newoption { trigger = "with-emscripten-pthreads", description = "Enables emscripten build to use posix threads" } +newoption { trigger = "with-mold-linker", description = "Tries to use the mold linker instead of the default linker of the toolchain" } newoption { trigger = "with-backend", description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.", @@ -102,7 +103,7 @@ function download_and_extract_sdl(sdl_url) print("Downloading: " .. sdl_url) local dest_dir = "src/thirdparty/" local local_file = dest_dir .. remote_sdl2_version .. ".zip" - local result_str, response_code = http.download(sdl_url, local_file) + local _, response_code = http.download(sdl_url, local_file) if response_code == 200 then print("Downloaded successfully to: " .. local_file) zip.extract(local_file, dest_dir) @@ -113,6 +114,22 @@ function download_and_extract_sdl(sdl_url) end end +function version_to_number( version ) + versionpart = 0 + versionnum = 0 + versionmod = 1000 + for str in string.gmatch(version, "[^%.]+") do + versionnum = versionnum + tonumber(str) * versionmod + versionpart = versionpart + 1 + if versionpart == 1 then + versionmod = 100 + elseif versionpart == 2 then + versionmod = 10 + end + end + return versionnum +end + function download_and_extract_dependencies() if not os.isdir("src/thirdparty/" .. remote_sdl2_version) then if _OPTIONS["windows-vc-build"] then @@ -210,6 +227,20 @@ function build_link_configuration( package_name, use_ee_icon ) end end + if _OPTIONS["with-mold-linker"] then + if _OPTIONS.platform == "clang" or _OPTIONS.platform == "clang-analyzer" then + linkoptions { "-fuse-ld=mold" } + else + gccversion = os.outputof( "gcc -dumpfullversion" ) + gccversionnumber = version_to_number( gccversion ) + if gccversionnumber >= 12110 then + linkoptions { "-fuse-ld=mold" } + else + linkoptions { "-B/usr/bin/mold" } + end + end + end + set_ios_config() set_xcode_config() build_arch_configuration() diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index f3ac06910..f182b3a25 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -186,7 +186,7 @@ true - --with-mojoal gmake + --with-mojoal --with-mold-linker gmake premake4 %{buildDir}../../../ ProjectExplorer.ProcessStep @@ -227,7 +227,7 @@ true - --with-mojoal gmake + --with-mold-linker --with-mojoal gmake premake4 %{buildDir}../../../ ProjectExplorer.ProcessStep