Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cppdialect is ignored in my Visual Studio 2022 solution #2230

Open
Jeanmilost opened this issue Jul 29, 2024 · 1 comment
Open

cppdialect is ignored in my Visual Studio 2022 solution #2230

Jeanmilost opened this issue Jul 29, 2024 · 1 comment
Labels

Comments

@Jeanmilost
Copy link

In order to deploy a Visual Studio 2022 solution, I'm using the following code:

newoption {
   trigger     = "device",
   value       = "DESKTOP|HANDHELD|IOT",
   description = "target device",
   default     = "DESKTOP",
   allowed = {
      { "DESKTOP",   "Desktop machine" },
      { "HANDHELD",  "Mobile device" },
      { "IOT",       "IoT device" }
   }
}

newoption {
   trigger     = "OPENGL",
   value       = "GL|GLES",
   description = "OpenGL support",
   default     = "GL",
   allowed = {
      { "GL",   "OpenGL" },
      { "GLES",  "OpenGLES" }
   }
}

newoption {
    trigger     = "VULKAN",
    description = "VULKAN support",
}

newoption {
    trigger     = "METAL",
    description = "METAL support (MacOS/iOS)",
}

newoption {
    trigger     = "DX12",
    description = "DX12 support (Windows)",
}


SDKDIR = "sdk.js"
BUILDDIR = "build.js"

defines { 
  "SCITERJS", "SCRIPT_JS",
  "JS_STRICT_NAN_BOXING", 
  "CONFIG_BIGNUM",
  "CONFIG_UNITS",  
  "CONFIG_JSX", 
  "CONFIG_JSX_SCITER",
  "CONFIG_DEBUGGER",
  "CONFIG_STORAGE",
  "CONFIG_OBJECT_LITERAL_CALL"
}

filter { "options:VULKAN" }
  defines {"USE_VULKAN", "SK_VULKAN"}
  includedirs { "$(VK_SDK_PATH)/Include" }  

filter { "options:METAL" }
  defines {"USE_METAL", "SK_METAL"}

filter { "options:DX12" }
  defines {"USE_DX12", "SK_DIRECT3D"}

filter { "options:OPENGL=GL" }
  defines {"USE_OPENGL", "SK_GL"}

filter { "options:OPENGL=GLES" }
  defines {"USE_OPENGLES", "SK_GL"}

filter {}

MONOLITHIC = true -- by design
USE_SKIA_BY_DEFAULT = true -- only rendering option on devices
WINDOWLESS = true

defines { "WINDOWLESS", "MONOLITHIC", "SCITER_BUILD",
          "DEVICE=" .. _OPTIONS["device"] }


include "premake5-modules.lua"

configurations { "Debug", "Release" }
platforms { "x32", "x64","arm32", "arm64" } 


function osabbr() 
  return os.target()
end

filter "system:windows"
  preferredtoolarchitecture "x86_64"
  --buildoptions "-Zm200"
  defines { "NOMINMAX" }
  location(BUILDDIR .. "/" .. osabbr())  
  platforms { "x32", "x64", "arm32", "arm64" }
  --configurations { "DebugSkia", "ReleaseSkia" }
  defines { "_CRT_SECURE_NO_WARNINGS" } 
  systemversion "latest"

filter "system:macosx"
  location(BUILDDIR .. "/" .. osabbr())  
  platforms { "x64" }  
filter "system:linux"
  location(BUILDDIR .. "/" .. osabbr() .. "/" .. string.lower(_OPTIONS["device"]))
  platforms { "x64", "arm32", "arm64" }  
filter "system:android"
  location(BUILDDIR .. "/" .. osabbr())  
  platforms { "x32", "x64", "arm32", "arm64" }  
filter {}


includedirs { 
  ".",     
  "engine",
  "engine/tool",
  "engine/gool",
  "engine/html",
  "engine/external/uv/include",
  "engine/external/uv-tls/include",
  "engine/external/zlib",
  "engine/external/minizip"
}  

filter "not system:linux"
  flags { "MultiProcessorCompile" } -- does not work reliably on Linux, why?
filter{}

cppdialect "C++17"
cdialect "C99"

staticruntime "On"

filter "platforms:x32"
  architecture "x86"
filter "platforms:x64"
  architecture "x86_64" 
filter "platforms:arm32"
  architecture "ARM" 
filter "platforms:arm64"
  architecture "ARM64" 

filter {"platforms:x32", "system:windows"}
  defines { "WIN32" }
filter {"platforms:x64", "system:windows"}
  defines { "WIN32","WIN64" }      
filter {"platforms:arm64", "system:windows"}
  defines { "WIN32","WIN64","ARM64" }      
  architecture "ARM64" 

filter "configurations:Debug*"
  defines { "DEBUG", "_DEBUG" }
  symbols "On"

filter "configurations:Release*"
  defines { "NDEBUG"}  
  optimize "Full"
  -- symbols "Off"
  flags { "LinkTimeOptimization" }

filter {"system:windows"}
  defines { "_CRT_SECURE_NO_WARNINGS" } 

filter { "system:macosx", "configurations:Release*" }
  linkoptions { "-s", "-flto=full" }

filter "system:linux"
  defines { "_GNU_SOURCE" }
  buildoptions {
    "`pkg-config fontconfig --cflags`",
    "-fPIC",
    "-Wno-unknown-pragmas",
    "-Wno-write-strings",
  }
  linkoptions { 
    "-fPIC",
    "-pthread",
    "-ldl",     
  } 

filter { "system:linux", "platforms:x32 or x64" }
  buildoptions {
    "-march=nehalem",
  }

filter { "system:linux", "platforms:arm32" }
  -- rapsberry Pi 2 and above
  buildoptions {
    "-mfpu=neon",
    "-mfloat-abi=hard",
  }
  linkoptions {
    "-mfpu=neon",
    "-mfloat-abi=hard",
  }


filter { "toolset:gcc", "files:*.cpp" }
  buildoptions {
    "-fpermissive",
    "-Wno-reorder",
  }

filter "system:android"
  buildoptions { "-fexceptions" }
  --optimize "Off"


filter {}

skia_includes()


workspace "sciter.lite"

--|
--| sciter dll
--|

project "sciter.lite"
  kind "SharedLib"
  language "C++"

  defines { "SCITER_EXPORTS" }
 
  filter "system:android"
    toolset "clang"
    --optimize "Off"
    defines { "ANDROID" }

  filter{}

  targetname "sciter"

  include_files_lite()
  include_files_tool()
  include_files_uv()
  include_files_uv_tls()  
  include_files_dybase()
  include_files_gool()
  include_files_zlib()
  include_files_minizip()
  include_files_png()
  include_files_jpeg()
  include_files_webp()
  include_files_rlottie()
  include_files_html()
  include_files_http()
  include_files_tmt()
  include_files_xdomjs()
  include_files_qjs()

  if os.target() == "windows" then
    --include_files_directshow()
    include_files_d2d()
  end
  --if os.target() == "linux" then    
  --  include_files_gtk()
  --elseif os.target() == "macosx" then
  --  include_files_osx()
  --end  
  include_files_xgl_skia()
  include_files_webgl() 
  include_freetype_files()

  filter "system:windows"
    prebuildcommands { 
        "subwcrev.exe \"%{wks.location}..\\..\" \"%{wks.location}..\\..\\engine\\sciter-revision-template.h\" \"%{wks.location}..\\..\\engine\\sciter-revision.h\"",
        "\"%{wks.location}..\\..\\".. SDKDIR .. "\\bin\\windows\\packfolder.exe\" \"%{wks.location}..\\..\\engine\\res.js\" \"%{wks.location}..\\..\\engine\\master-css-resources-js.cpp\"  -v \"master_css_resources\"" }
  filter {}

  targetdir (SDKDIR .. "/bin.lite/" .. osabbr() .. "/%{cfg.platform}")


  filter "system:windows"
    links { "usp10", "ws2_32", "wininet", "windowscodecs" }
    files { 
      "engine/lite/windows/dllmain.cpp",       
      "engine/lite/windows/sciter.def", 
      "engine/lite/windows/sciter.dll.rc", 
      "engine/lite/windows/lite-d2d.cpp", 
    }

  filter "system:macosx"
    links { 
      "CoreFoundation.framework", 
      "Cocoa.framework",
      "Carbon.framework", 
      "AVFoundation.framework",
      "SystemConfiguration.framework",
      "CoreMedia.framework",
      "CoreText.framework",
      "CoreGraphics.framework",
      "CoreData.framework",
      "CoreVideo.framework",
      "IOKit.framework",
      "OpenGL.framework"
    } 

  filter "system:linux"
    linkoptions { 
       "`pkg-config fontconfig --libs`",
       "-fPIC",
       "-pthread",
       "-Wl,--no-undefined",
       "-lX11", "-lX11-xcb",
       "-ldl",
       "-latomic",
    }

  filter { "system:linux", "options:OPENGL=GL" }
    linkoptions { 
       "-lGL",
       "-lGLU"
    }
  filter { "system:linux", "options:OPENGL=GLES" }
    linkoptions { 
       "-lGL",
       "-lEGL",
       "-lGLESv2",
    }

  filter "system:android"
    buildoptions { "-Wreorder" }
    links {"GLESv2","GLESv1_CM","EGL","m"}

  filter {}  

workspace "sciter.lite.static"

project "sciter.lite.static"
  kind "StaticLib"
  language "C++"

  defines { "STATIC_LIB" }
  
  targetname "sciter.static"

  targetdir (BUILDDIR .. "/lib." .. osabbr() .."/%{cfg.platform}lite")

  includedirs { 
    "engine/tiscript/include" 
  }

  include_files_lite()
  include_files_tool()
  include_files_uv()
  include_files_uv_tls()  
  include_files_dybase()
  include_files_gool()
  include_files_zlib()
  include_files_png()
  include_files_jpeg()
  include_files_webp()
  include_files_rlottie()
  include_files_html()
  include_files_http()
  include_files_tmt()
  include_files_xdom()
  include_files_xgl_skia()      
  include_files_webgl()  
  include_freetype_files()

  filter "system:macosx"
    links { 
      "CoreFoundation.framework", 
      "Cocoa.framework",
      "Carbon.framework", 
      "AVFoundation.framework",
      "SystemConfiguration.framework",
      "CoreMedia.framework",
      "CoreText.framework",
      "CoreGraphics.framework",
      "CoreData.framework",
      "CoreVideo.framework",
      "IOKit.framework",
      "OpenGL.framework"
    } 
  filter {}  

-- include "sdk"

This code globally works well, except for the cppdialect "C++17" instruction, which is completely ignored. Indeed all my projects remain configured to <LanguageStandard>stdcpplatest</LanguageStandard> instead of <LanguageStandard>stdcpp17</LanguageStandard> after the deployment.

I already asked this question here: https://stackoverflow.com/questions/78766168/premake5-cppdialect-is-ignored-while-creating-project-for-vs2022, unfortunately it remained unresolved.

Can you please tell me what I need to change in my above code to make the cppdialect instruction to be applied during the deployment?

@samsinsane
Copy link
Member

This code globally works well, except for the cppdialect "C++17" instruction, which is completely ignored. Indeed all my projects remain configured to <LanguageStandard>stdcpplatest</LanguageStandard> instead of <LanguageStandard>stdcpp17</LanguageStandard> after the deployment.

For VS2022, Premake will only emit stdcpplatest if cppdialect is explicitly set to "C++latest". You can see the logic here:

function m.languageStandard(cfg, condition)
if _ACTION >= "vs2017" then
if (cfg.cppdialect == "C++14") then
m.element("LanguageStandard", condition, 'stdcpp14')
elseif (cfg.cppdialect == "C++17") then
m.element("LanguageStandard", condition, 'stdcpp17')
elseif (cfg.cppdialect == "C++20") then
m.element("LanguageStandard", condition, iif(_ACTION == "vs2017", 'stdcpplatest', 'stdcpp20'))
elseif (cfg.cppdialect == "C++latest") then
m.element("LanguageStandard", condition, 'stdcpplatest')
end
end
end

With just the snippet you've provided above, I can't provide much more assistance beyond recommending that you look at premake5-modules.lua and skia_includes().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants