Intro to Premake and Build Systems | C++ For Java Devs Ep. 6

Поділитися
Вставка
  • Опубліковано 30 лип 2024
  • Join the Discord: / discord
    In this episode I go over a quick introduction to what a build system is and why we need it, then I describe how to create a premake file and generate a Visual Studio solution using the premake file.
    Premake: premake.github.io/
    Source Code/Build Files for this Episode: gist.github.com/codingminecra...
    0:00 In This Episode
    2:56 Premake Installation & Docs
    3:23 Setting up the File Structure
    5:33 Creating the First Premake File
    14:11 Generating Build Files using Premake
    15:41 Exploring Generated VS Project
    16:55 Updating Build.bat
    22:04 Adding a "Clean" Action
    24:35 Fixing a Bug
    25:20 Challenge
    ---------------------------------------------------------------------
    Website: ambrosiogabe.github.io/
    Github: github.com/ambrosiogabe
    Here are some books I recommend if you want to learn about game engine development more thoroughly. I do not profit off any of these sales, these are just some books that have helped me out :)
    My Recommended Game Engine Books:
    Game Engine Architecture: www.gameenginebook.com/
    Game Physics Cookbook (Read this before the next physics book): www.amazon.com/Game-Physics-C...
    Game Physics (Ian Millington): www.amazon.com/Game-Physics-E...
    Game Programming Patterns (Free): gameprogrammingpatterns.com/
    My Recommended Beginning Game Programming Books:
    JavaScript Game Design: www.apress.com/gp/book/978143...
    My Recommended Java Books:
    Data Structures/Algorithms: www.amazon.com/Data-Structure...
    LWJGL (Free, but I haven't read this thoroughly): lwjglgamedev.gitbooks.io/3d-g...

КОМЕНТАРІ • 27

  • @postedactive
    @postedactive 3 роки тому +5

    Honest, this is amazing stuff. Can't wait for the next one to go up.

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +2

      Hey @PostedActive, I really appreciate the comment! The C++ series hasn't been doing as well as the game engine series so I was wondering if people were finding it useful haha. The next episode should be going up tomorrow morning though :)

    • @postedactive
      @postedactive 3 роки тому +2

      @@GamesWithGabe Take it from this dude. They're an immense help if that's worth anything. Probably series just needs more Clickbait is all 😂 cause the material itself is going very well. I'll have my IDE ready, cheers mate 👍.

  • @FunGameDeveloper
    @FunGameDeveloper 3 роки тому +2

    very good, congratulations for your work!

  • @abhay29
    @abhay29 2 роки тому +1

    Great Tutorial !

  • @wolfdesroyer8711
    @wolfdesroyer8711 3 роки тому +8

    FOR LINUX AND MAC USERS
    I made a the bash script that works on mac and linux you just have to put both of the binaries and the vendor folder and call the mac one premake5mac and the linux one premake5lin and I've removed the compile option because I'm lazy and people can just compile it with whatever IDE there using. It should auto detect the OS but if it doesn't then just add linux or mac after the action to select your OS. Also let me know if there are any problems because I'm not that good at writing in bash. :)
    Examples:
    ./build.sh gmake2 linux
    ./build.sh xcode4
    #!/bin/sh
    PrintHelp()
    {
    echo Enter 'build.sh action' where action is one of the following:
    echo
    echo clean Remove all binaries and generated files
    echo codelite Generate CodeLite project files
    echo gmake Generate GNU makefiles for POSIX, MinGW, and Cygwin
    echo gmake2 Generate GNU makefiles for POSIX, MinGW, and Cygwin
    echo vs2005 Generate Visual Studio 2005 project files
    echo vs2008 Generate Visual Studio 2008 project files
    echo vs2010 Generate Visual Studio 2010 project files
    echo vs2012 Generate Visual Studio 2012 project files
    echo vs2013 Generate Visual Studio 2013 project files
    echo vs2015 Generate Visual Studio 2015 project files
    echo vs2017 Generate Visual Studio 2017 project files
    echo vs2019 Generate Visual Studio 2019 project files
    echo xcode4 Generate Apple Xcode 4 project files
    }
    if [ "$1" = "" ] ;then
    PrintHelp
    else
    if [ "$2" = "mac" ] ;then
    echo using mac
    ./vendor/premake5mac $1
    exit
    fi
    if [ "$2" = "linux" ] ;then
    echo using linux
    ./vendor/premake5lin $1
    exit
    fi
    if [ "$(uname)" = "Darwin" ]; then
    echo using mac
    ./vendor/premake5mac $1
    elif [ "$(expr substr "$(uname -s)" 1 5)" = "Linux" ]; then
    echo using linux
    ./vendor/premake5lin $1
    fi
    fi

  • @eXtremeElectronics
    @eXtremeElectronics 4 місяці тому

    Very helpful

  • @RenatoSousaRS
    @RenatoSousaRS 3 роки тому +1

    Very nice!

  • @erik9817
    @erik9817 6 місяців тому

    Interesting video. Do you consider the generated solutions as part of the code that should be checked into source control? It appears, using premake5, one can generate solutions at any time and consider them "generated". Then the question is, since the solution file is sure to change over time, are these changes important to track in source control?

    • @GamesWithGabe
      @GamesWithGabe  6 місяців тому +1

      I don’t put generated solutions in source control. I make sure to re-generate the solutions before committing though so that anyone that clones the repository will end up with the same files (and you could add a pre-commit hook if you wanted that does this). But I believe the general consensus is that any generated files should stay out of source control :)

    • @erik9817
      @erik9817 6 місяців тому

      Thanks! @@GamesWithGabe

  • @DieserDeutscheTyp
    @DieserDeutscheTyp 3 роки тому +1

    Good day, nice tutorial but i still have a problem when i type in my pathf(vendor/bin/premake/premake5.exe) a error cold (Der Befehl "vendor" ist entweder falsch geschrieben oder
    konnte nicht gefunden werden.) appear what i can do?

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      Hey @FyMa2618! Which operating system are you running? I'm guessing windows since you downloaded the .exe version. If you're on windows try doing .\vendor\bin\premake5.exe with the . In front and using \ instead of /. Also, make sure you're premake5.exe is in the folder vendor/bin/premake. All I'm doing when I type in that command is running the premake exe, so as long as you have the correct path it should work out :)

    • @DieserDeutscheTyp
      @DieserDeutscheTyp 3 роки тому

      @@GamesWithGabe Good day, he finds but it say: "invalid value 'C++19' for cppdialect". My Code is:"
      workspace "GotGames"
      architecture "x64"
      configurations
      {
      "Debug",
      "Release",
      "Dist"
      }
      outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
      project "GotGames"
      location "GotGames"
      kind "SharedLib"
      language "C++"
      targetdir ("bin/" .. outputdir .. "/%{prj.name}")
      objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
      files
      {
      "%{prj.name}/src/**.h",
      "%{prj.name}/src/**.cpp"
      }
      includedirs
      {
      "%{prj.name}/vendor/spdlog/include"
      }
      filter "system:windows"
      cppdialect "C++19"
      staticruntime "On"
      systemversion "latest"
      defines
      {
      "GG_PLATFORM_WINDOWS",
      "GG_BUILD_DLL"
      }
      postbuildcommands
      {
      ("{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/SandBoxGame")
      }
      filter "configurations:Debug"
      defines "GG_DEBUG"
      symbols "On"
      filter "configurations:Release"
      defines "GG_RELEASE"
      optimize "On"
      filter "configurations:Dist"
      defines "GG_DIST"
      optimize "On"
      project "SandBoxGame"
      location "SandBoxGame"
      kind "ConsoleApp"
      language "C++"
      targetdir ("bin/" .. outputdir .. "/%{prj.name}")
      objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
      files
      {
      "%{prj.name}/src/**.h",
      "%{prj.name}/src/**.cpp"
      }
      includedirs
      {
      "GotGames/vendor/spdlog/include",
      "GotGames/src"
      }
      links
      {
      "GotGames"
      }
      filter "system:windows"
      cppdialect "C++19"
      staticruntime "On"
      systemversion "latest"
      defines
      {
      "GG_PLATFORM_WINDOWS"
      }
      filter "configurations:Debug"
      defines "GG_DEBUG"
      symbols "On"
      filter "configurations:Release"
      defines "GG_RELEASE"
      optimize "On"
      filter "configurations:Dist"
      defines "GG_DIST"
      optimize "On" "
      I am dont no why can did you can help me?

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      @@DieserDeutscheTyp that would be because C++19 isn't a valid C++ version. If you're having trouble with your premake scripts I would highly suggest you take a look at the premake documentation: github.com/premake/premake-core/wiki/cppdialect

  • @brendonlantz5972
    @brendonlantz5972 3 роки тому +2

    I like premake much better than cmake, but I haven't seen much on vcpkg integration for the libraries.

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +1

      Hey Brendon, I've never used vcpkg and I was reading up on it and couldn't tell what makes it any better then just distributing the binaries for a project. I was wondering if you could let me know what vcpkg is primarily used for, or point me to some resources so I can learn a bit about it :)

    • @brendonlantz5972
      @brendonlantz5972 3 роки тому +1

      @@GamesWithGabe For vcpkg it essentially manages libraries on your machine and cmake can integrate with it to know where the libraries are. So you can make a cmake lists with find(glfw) and it will be able to find them on whatever platform you're on (assuming vcpkg is installed). Conan is also similar but I found it less intuitive. If you are managing libraries directly you will have to somehow account for the different platforms and where the libraries are. It integrates with visual studio, and this is where I learned about it -

    • @brendonlantz5972
      @brendonlantz5972 3 роки тому

      @@GamesWithGabe ua-cam.com/video/ijmZKRIfoOI/v-deo.html

    • @brendonlantz5972
      @brendonlantz5972 3 роки тому

      of course git submodules and keeping the library source in the project are ways around this problem as well. There are lots of different approaches.

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +3

      @@brendonlantz5972 Gotcha, that makes more sense. I wish C++ had one central package manager like npm or pip. But maybe one day it will :)

  • @davidmarinho2848
    @davidmarinho2848 3 роки тому +1

    Linux bash script.
    First, of all, I want to thank you Gabe, your tutorials have been amazing! I am learning a lot of new things. Step by step, I am closer to building a 3d game engine.
    One more time, thank you for your help, your tutorials have been very helpful. Just keep going and keep lunching that great content :).
    I also will let the bash script code for you all ;).
    Code for linux:
    --------
    # If there are no arguments or if the argument is equivalent to "help"
    if [ "$1" == "" ] || [ "$1" == "help" ]
    then
    # echo -e allow us to use arguments, like
    that breaks the line
    echo -e "
    "
    echo "Enter 'build.bat action' where action is one of the following:"
    echo -e "
    "
    echo "create_project Will create the resources needed to a new project into the current directory"
    echo "compile Will generate make file then compile using the make file."
    echo "run Will generate make file then compile using the make file then run the project"
    echo "clean Remove all binaries and intermediate binaries and project files."
    echo "codelite Generate CodeLite project files"
    echo "gmake2 Generate GNU makefiles for Linux"
    echo "vs2005 Generate Visual Studio 2005 project files"
    echo "vs2008 Generate Visual Studio 2008 project files"
    echo "vs2010 Generate Visual Studio 2010 project files"
    echo "vs2012 Generate Visual Studio 2012 project files"
    echo "vs2013 Generate Visual Studio 2013 project files"
    echo "vs2015 Generate Visual Studio 2015 project files"
    echo "vs2017 Generate Visual Studio 2017 project files"
    echo "vs2019 Generate Visual Studio 2019 project files"
    echo "xcode4 Generate Apple Xcode 4 project files"
    elif [ "$1" == "compile" ]
    then
    # Create makefile gmake
    ./vendor/premake5 gmake
    make
    elif [ "$1" == "run" ]
    then
    # Create makefile gmake
    ./vendor/premake5 gmake
    make
    # Run
    cd bin
    # Create a variable that will get the folder that has the word "...linux..." in its name
    var=$(find -name *linux*)
    ./$var/ProjectFolder/ProjectFolder
    cd ..
    fi
    exit
    --------
    P.S.: I don't know why, but in the lua's file inside of Project folder, you have to delete the lines:
    buildoptions "/MTd"
    buildoptions "/MT"
    If someone knows why I would love to receive an explanation :D
    Edit: I just kept working on the file and it is becoming pretty cool (I guess ahaha) so I will let a link bellow if you want take a look
    github.com/davidalmarinho/beaver