diff --git a/Build/Sharpmake/Sharpmake.Application b/Build/Sharpmake/Sharpmake.Application new file mode 100755 index 0000000..54362b3 Binary files /dev/null and b/Build/Sharpmake/Sharpmake.Application differ diff --git a/Build/netImgui.sharpmake.cs b/Build/netImgui.sharpmake.cs index 9cde161..9da12e3 100644 --- a/Build/netImgui.sharpmake.cs +++ b/Build/netImgui.sharpmake.cs @@ -90,7 +90,14 @@ public override void ConfigureAll(Configuration conf, NetImguiTarget target) conf.Options.Add(new Options.Vc.Linker.DisableSpecificWarnings("4099")); //Prevents: warning LNK4099: PDB '' was not found with 'glfw3_mtd.lib(context.c.obj)' or at ''; linking object as if no debug info //--------------------------------------------- - conf.EventPostBuild.Add("xcopy \"" + NetImguiTarget.GetPath(@"\Code\ServerApp\Background.png") + "\" \"" + conf.TargetPath + "\" /D /Y"); + if (target.DevEnv == DevEnv.xcode4ios) + { + conf.Options.Add(new Sharpmake.Options.XCode.Compiler.InfoPListFile(NetImguiTarget.GetPath(@"/Code/ServerApp/info.plist"))); + } + else + { + conf.EventPostBuild.Add("xcopy \"" + NetImguiTarget.GetPath(@"\Code\ServerApp\Background.png") + "\" \"" + conf.TargetPath + "\" /D /Y"); + } } private string getGlfwLibName(Platform platform, DevEnv developerEnv) @@ -102,7 +109,9 @@ private string getGlfwLibName(Platform platform, DevEnv developerEnv) libName += "-vc2019"; } else if( developerEnv == DevEnv.vs2017 ) { libName += "-vc2017"; - } + } else if( developerEnv == DevEnv.xcode4ios ) { + libName += "-macos-universal"; + } if (platform == Platform.win64) { libName += "-64"; diff --git a/Build/readme.txt b/Build/readme.txt index bf07500..33b3f6f 100644 --- a/Build/readme.txt +++ b/Build/readme.txt @@ -1,5 +1,5 @@ This folder contains files needed to generate the various NetImgui projects. -User can safely ignore its content; only "GenerateProject.bat" needs calling. +User can safely ignore its content; only "GenerateProject.bat" needs calling, or "GenerateProject.sh" on macOS. Optionally, "GenerateCompatibilityTest.bat" can be called to get older versions of Dear ImGui and test compatibility of NetImgui against all of them. diff --git a/Build/shared.sharpmake_mac.cs b/Build/shared.sharpmake_mac.cs new file mode 100644 index 0000000..27dde1c --- /dev/null +++ b/Build/shared.sharpmake_mac.cs @@ -0,0 +1,390 @@ +// NetImgui.sharpmake.cs +using Sharpmake; +using System; +using System.Collections.Generic; +using System.Text; +using System.Linq; +using System.IO; +using System.Text.RegularExpressions; +using ProjConfig = Sharpmake.Project.Configuration; + +namespace NetImgui +{ + //============================================================================================= + // CUSTOM PROPERTIES + //============================================================================================= + // Target Compiler options + [Fragment, Flags] + public enum Compiler + { + MSBuild = 1 << 1, + Clang = 1 << 2 + } + + // Target Config + public class NetImguiTarget : ITarget + { + // DevEnv and Platform are mandatory on all targets so we define them. + public DevEnv DevEnv; + public Platform Platform; + public Compiler Compiler; + public Optimization Optimization; + + public NetImguiTarget() + { + DevEnv = DevEnv.xcode4ios; + Platform = Platform.mac; + Optimization = Optimization.Debug | Optimization.Release; + Compiler = Compiler.Clang; + } + + // Generates a solution for each Visual Studio version found + // Note: Add a Clang target when detected installed for that Visual Studio version + static public NetImguiTarget[] CreateTargets() + { + List targets = new List(); + + targets.Add(new NetImguiTarget{DevEnv = DevEnv.xcode4ios, Compiler = Compiler.Clang}); + + return targets.ToArray(); + } + + static public string GetPath(string pathFromRoot) + { + return Directory.GetCurrentDirectory() + pathFromRoot; + } + } + + //============================================================================================= + // SHADERS COMPILATION TASK + //============================================================================================= + public class CustomBuildFileHLSL : ProjConfig.CustomFileBuildStep + { + public enum ShaderProfile + { + ps_5_0, + vs_5_0, + cs_5_0, + } + + public CustomBuildFileHLSL(ProjConfig conf, string targetName, ShaderProfile shaderProfile, string entryPoint, string outputDir, string sourceFile) + { + KeyInput = sourceFile; + string resourceName = Path.GetFileNameWithoutExtension(sourceFile); + + Output = string.Format(@"{0}\{1}.h", outputDir, resourceName); + Description = "Shader (" + shaderProfile.ToString() + ") : " + sourceFile; + Executable = ""; // Setting 'fxc' exe in ExeArgs instead, avoid build system adding a uneeded dependency to 'fxc' + ExecutableArguments = string.Format("fxc /Zi /nologo /O2 /E\"{0}\" /T {1} /Fh\"{2}\" /Vn\"gpShader_{3}\" \"{4}\"", entryPoint, shaderProfile.ToString(), Output, resourceName, sourceFile); + } + + public static void AddFilesExt(Project project) + { + project.SourceFilesExtensions.Add(".hlsl"); + } + + public static void ClaimAllShaderFiles(Project project) + { + ClaimShaderFiles(project, "VS.hlsl", ShaderProfile.vs_5_0, "main"); + ClaimShaderFiles(project, "PS.hlsl", ShaderProfile.ps_5_0, "main"); + ClaimShaderFiles(project, "CS.hlsl", ShaderProfile.cs_5_0, "main"); + } + + public static void ClaimShaderFiles(Project project, string filenameEnding, ShaderProfile shaderProfile, string entryName) + { + Strings hlsl_Files = new Strings(project.ResolvedSourceFiles.Where(file => file.EndsWith(filenameEnding, StringComparison.InvariantCultureIgnoreCase))); + if (hlsl_Files.Count() > 0) + { + foreach (ProjConfig conf in project.Configurations) + { + string targetName = conf.Target.Name; + string outputDir = string.Format(@"{0}\{1}_{2}\", NetImguiTarget.GetPath(@"\_generated\Shaders"), project.Name, conf.Target.GetOptimization()); + conf.IncludePaths.Add(outputDir); + foreach (string file in hlsl_Files) + { + CustomBuildFileHLSL HlslCompileTask = new CustomBuildFileHLSL(conf, targetName, shaderProfile, entryName, outputDir, Project.GetCapitalizedFile(file)); + project.ResolvedSourceFiles.Add(HlslCompileTask.Output); + conf.CustomFileBuildSteps.Add(HlslCompileTask); + } + } + } + } + } + + //============================================================================================= + // PROJECTS + //============================================================================================= + [Sharpmake.Generate] + public class ProjectBase : Project + { + public ProjectBase(bool isExe) + : base(typeof(NetImguiTarget)) + { + CustomBuildFileHLSL.AddFilesExt(this); + IsFileNameToLower = false; + IsTargetFileNameToLower = false; + mIsExe = isExe; + AddTargets(NetImguiTarget.CreateTargets()); + } + + protected override void ExcludeOutputFiles() + { + base.ExcludeOutputFiles(); + CustomBuildFileHLSL.ClaimAllShaderFiles(this); + } + + [Configure()] + public virtual void ConfigureAll(Configuration conf, NetImguiTarget target) + { + conf.Name = @"[target.Compiler]_[target.Optimization]"; + conf.ProjectFileName = @"[project.Name]"; + conf.TargetFileSuffix = @"_[target.Optimization]"; + conf.ProjectPath = NetImguiTarget.GetPath(@"/_projects\[target.DevEnv]"); + conf.TargetPath = NetImguiTarget.GetPath( mIsExe ? @"/_Bin/[target.DevEnv]_[target.Compiler]_[target.Platform]" + : @"\_generated/Libs\[target.DevEnv]_[target.Compiler]_[target.Platform]"); + conf.IntermediatePath = NetImguiTarget.GetPath(@"/_intermediate\[target.DevEnv]_[target.Compiler]_[target.Platform]_[target.Optimization]/[project.Name]"); + conf.Output = mIsExe ? Project.Configuration.OutputType.IosApp : Project.Configuration.OutputType.Lib; + + conf.IncludePaths.Add(NetImguiTarget.GetPath(ProjectImgui.sDefaultPath) + @"\backends"); + + if (mIsExe) + { + conf.IncludePaths.Add(NetImguiTarget.GetPath(@"/Code")); + } + + //conf.Defines.Add("JSON_NOEXCEPTION"); // Prevents error in VisualStudio c++ library with NoExcept, like xlocale + conf.Defines.Add("IMGUI_DISABLE_OBSOLETE_FUNCTIONS"); // Enforce using up to date Dear ImGui Api (In Server, Compatibility tests and Samples) + + conf.Options.Add(new Sharpmake.Options.XCode.Compiler.SystemFrameworks("AppKit")); + conf.Options.Add(new Sharpmake.Options.XCode.Compiler.SystemFrameworks("IOKit")); + conf.Options.Add(new Sharpmake.Options.XCode.Compiler.SystemFrameworks("CoreFoundation")); + conf.Options.Add(new Sharpmake.Options.XCode.Compiler.SystemFrameworks("CoreGraphics")); + conf.Options.Add(new Sharpmake.Options.XCode.Compiler.MacOSDeploymentTarget("13.0")); + conf.Options.Add(Sharpmake.Options.XCode.Compiler.Exceptions.Enable); + } + + // Add sources files for platform specific Dear ImGui backend (OS/Renderer support) + public void AddImguiBackendSources() + { + SourceFiles.Add(NetImguiTarget.GetPath(ProjectImgui.sDefaultPath) + @"\backends\imgui_impl_glfw.h"); + SourceFiles.Add(NetImguiTarget.GetPath(ProjectImgui.sDefaultPath) + @"\backends\imgui_impl_glfw.cpp"); + SourceFiles.Add(NetImguiTarget.GetPath(ProjectImgui.sDefaultPath) + @"\backends\imgui_impl_opengl3.h"); + SourceFiles.Add(NetImguiTarget.GetPath(ProjectImgui.sDefaultPath) + @"\backends\imgui_impl_opengl3.cpp"); + } + + public void AddDependencyImguiIndex16(Configuration conf, NetImguiTarget target) + { + conf.AddPublicDependency(target); + EnabledImguiIndex16Bits(conf); + } + + public void AddDependencyImguiIndex32(Configuration conf, NetImguiTarget target) + { + conf.AddPublicDependency(target); + EnabledImguiIndex32Bits(conf); + } + + public void AddDependencyImguiServer(Configuration conf, NetImguiTarget target) + { + conf.AddPublicDependency(target); + EnabledImguiIndex32Bits(conf); + } + + public void EnabledImguiIndex16Bits(Configuration conf) + { + } + + public void EnabledImguiIndex32Bits(Configuration conf) + { + conf.Defines.Add("ImDrawIdx=unsigned int"); + } + + bool mIsExe; + } + + //--------------------------------------------------------------------------------------------- + // IMGUI Project + //--------------------------------------------------------------------------------------------- + [Sharpmake.Generate] + public class ProjectImgui : ProjectBase + { + public ProjectImgui() + : base(false) + { + SourceRootPath = NetImguiTarget.GetPath(sDefaultPath); + SourceFilesExcludeRegex.Add(@"backends\.*"); + } + + public static string sDefaultPath = @"/Code/ThirdParty/DearImgui"; + } + + // Dear ImGui Library, 16bits index + [Sharpmake.Generate] + public class ProjectImguiIndex16 : ProjectImgui + { + public ProjectImguiIndex16() { Name = "DearImguiIndex16Lib"; } + + public override void ConfigureAll(Configuration conf, NetImguiTarget target) + { + base.ConfigureAll(conf, target); + EnabledImguiIndex16Bits(conf); + } + } + + // Dear ImGui Library, 32bits index + [Sharpmake.Generate] + public class ProjectImguiIndex32 : ProjectImgui + { + public ProjectImguiIndex32() { Name = "DearImguiIndex32Lib"; } + + public override void ConfigureAll(Configuration conf, NetImguiTarget target) + { + base.ConfigureAll(conf, target); + EnabledImguiIndex32Bits(conf); + } + } + + // Dear ImGui Library, 32bits index & 64 bits textureID + [Sharpmake.Generate] + public class ProjectImguiServer : ProjectImgui + { + public ProjectImguiServer() { Name = "DearImguiServerLib"; } + + public override void ConfigureAll(Configuration conf, NetImguiTarget target) + { + base.ConfigureAll(conf, target); + conf.Defines.Add("ImTextureID=ImU64"); // Server must absolutly use at minimum 64bits texture id, even when compiled in 32 bits + EnabledImguiIndex32Bits(conf); + conf.LibraryFiles.Add("glfw3"); + } + } + + //--------------------------------------------------------------------------------------------- + // NETIMGUI Project + //--------------------------------------------------------------------------------------------- + [Sharpmake.Generate] + public class ProjectNetImgui : ProjectBase + { + public ProjectNetImgui(string imguiFullPath) + : base(false) + { + mVersion = Path.GetFileName(imguiFullPath); + mImguiPath = imguiFullPath; + Name = "NetImguiLib (" + mVersion + ")"; + SourceRootPath = NetImguiTarget.GetPath(@"\Code\Client"); + SourceFiles.Add(mImguiPath + @"\imgui.h"); + } + + public override void ConfigureAll(Configuration conf, NetImguiTarget target) + { + base.ConfigureAll(conf, target); + conf.Options.Add(Options.Vc.General.WarningLevel.EnableAllWarnings); + conf.IncludePaths.Add(mImguiPath); + //conf.LibraryFiles.Add("ws2_32.lib"); + } + string mVersion; + string mImguiPath; + } + + [Sharpmake.Generate] + public class ProjectSample : ProjectBase + { + public ProjectSample(string inName, bool useIndex32=false) + : base(true) + { + Name = inName; + mUseIndex32 = useIndex32; + SourceRootPath = NetImguiTarget.GetPath(@"\Code\Sample\") + Name; + AdditionalSourceRootPaths.Add(NetImguiTarget.GetPath(@"\Code\Sample\Common")); + AddImguiBackendSources(); + } + + public override void ConfigureAll(Configuration conf, NetImguiTarget target) + { + base.ConfigureAll(conf, target); + if( mUseIndex32 == false ){ + AddDependencyImguiIndex16(conf, target); + conf.AddPublicDependency(target); + } + else + { + AddDependencyImguiIndex32(conf, target); + conf.AddPublicDependency(target); + } + conf.IncludePaths.Add(NetImguiTarget.GetPath(ProjectImgui.sDefaultPath)); + conf.IncludePaths.Add(NetImguiTarget.GetPath(@"\Code\Client")); + } + bool mUseIndex32; + } + + // Compile a console program, with Dear ImGui and NetImgui sources + // included directly. The Dear ImGui code does not include any backend, + // only try connecting the the NetImgui Server to draw its content remotely. + [Sharpmake.Generate] + public class ProjectNoBackend : ProjectBase + { + public ProjectNoBackend(string inName, string inImguiFullPath) + : base(true) + { + mImguiFullPath = string.IsNullOrEmpty(inImguiFullPath) ? NetImguiTarget.GetPath(ProjectImgui.sDefaultPath) : inImguiFullPath; + Name = inName; + SourceRootPath = NetImguiTarget.GetPath(@"\Code\Sample\SampleNoBackend"); + + // Find the Dear Imgui Sources files + string[] sourceExtensions = new string[]{".h",".cpp"}; + var files = Directory.EnumerateFiles(mImguiFullPath, "*.*", SearchOption.TopDirectoryOnly); + foreach (var file in files) + { + if (sourceExtensions.Contains(Path.GetExtension(file), StringComparer.OrdinalIgnoreCase)){ + //Console.WriteLine("File Added: {0}", Path.GetFullPath(file)); + SourceFiles.Add(Path.GetFullPath(file)); + } + }; + } + + public override void ConfigureAll(Configuration conf, NetImguiTarget target) + { + base.ConfigureAll(conf, target); + conf.IncludePaths.Add(mImguiFullPath); + conf.IncludePaths.Add(NetImguiTarget.GetPath(@"\Code\Client")); + conf.Options.Add(Options.Vc.Linker.SubSystem.Console); + conf.LibraryFiles.Add("ws2_32.lib"); + + // Remove a some Dear ImGui sources compile warning + if( target.Compiler == Compiler.MSBuild ){ + conf.Options.Add(new Options.Vc.Compiler.DisableSpecificWarnings("4100")); // warning C4100: xxx: unreferenced formal parameter + conf.Options.Add(new Options.Vc.Compiler.DisableSpecificWarnings("4189")); // warning C4189: xxx: unused local variable + } + else if ( target.Compiler == Compiler.Clang ){ + conf.Options.Add(Options.Vc.General.PlatformToolset.ClangCL); + conf.AdditionalCompilerOptions.Add("-Wno-unknown-warning-option"); + conf.AdditionalCompilerOptions.Add("-Wno-unused-parameter"); + conf.AdditionalCompilerOptions.Add("-Wno-unused-variable"); + conf.AdditionalCompilerOptions.Add("-Wno-unused-but-set-variable"); + } + } + string mImguiFullPath; + } + + //============================================================================================= + // SOLUTIONS + //============================================================================================= + public class SolutionBase : Sharpmake.Solution + { + public SolutionBase(string inName) + : base(typeof(NetImguiTarget)) + { + Name = inName; + IsFileNameToLower = false; + AddTargets(NetImguiTarget.CreateTargets()); + } + + [Configure()] + public virtual void ConfigureAll(Configuration conf, NetImguiTarget target) + { + conf.Name = "[target.Compiler]_[target.Optimization]"; + conf.SolutionFileName = "[target.DevEnv]_[solution.Name]"; + conf.SolutionPath = NetImguiTarget.GetPath(@"\_projects"); + } + } +} \ No newline at end of file diff --git a/Code/ServerApp/info.plist b/Code/ServerApp/info.plist new file mode 100644 index 0000000..4076f31 --- /dev/null +++ b/Code/ServerApp/info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.yourcompany.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSPrincipalClass + + + diff --git a/Code/ThirdParty/glfw/lib-macos-universal/libglfw.3.dylib b/Code/ThirdParty/glfw/lib-macos-universal/libglfw.3.dylib new file mode 100755 index 0000000..06008d7 Binary files /dev/null and b/Code/ThirdParty/glfw/lib-macos-universal/libglfw.3.dylib differ diff --git a/Code/ThirdParty/glfw/lib-macos-universal/libglfw3.a b/Code/ThirdParty/glfw/lib-macos-universal/libglfw3.a new file mode 100644 index 0000000..7750656 Binary files /dev/null and b/Code/ThirdParty/glfw/lib-macos-universal/libglfw3.a differ diff --git a/GenerateProject.sh b/GenerateProject.sh new file mode 100755 index 0000000..1ecdc1e --- /dev/null +++ b/GenerateProject.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +cd "$(dirname "$0")" + +# Detect if the compatibility.sharpmake.cs file exists, and set CompatibilityCS accordingly +CompatibilityCS="Build/nocompatibility.sharpmake.cs" +if [ -f "_generated/imgui/compatibility.sharpmake.cs" ]; then + CompatibilityCS="_generated/imgui/compatibility.sharpmake.cs" +fi + +./Build/Sharpmake/Sharpmake.Application "/sources(@'Build/shared.sharpmake_mac.cs', @'$CompatibilityCS', @'Build/netImgui.sharpmake.cs') /verbose() " + +if [ "$1" = "1" ]; then + exit 0 +fi + +read -p "Press any key to continue..." \ No newline at end of file diff --git a/README.md b/README.md index 29b992e..146c34e 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Here is a quick overview of the logic behind using the **NetImgui Server** and o **6. Go back to 1** #### Note -The NetImgui Server application currently compiles under Windows, but few changes are required to properly have it running under other Operating Systems. +The NetImgui Server application currently compiles under Windows and Mac, but few changes are required to properly have it running under other Operating Systems. To compile for Mac, modify NetImguiServer_App.h to enable the GLFW_GL3 rendering API. # Integration 1. Download the [latest version](https://github.com/sammyfreg/netImgui/releases "latest version") of the **NetImgui** library.