A bunch of dependency management scripts for premake5.
- Add this repository as a submodule:
$ git submodule add https://github.com/Cvelth/third_party third_party - Add
third_party.ymlconfig file to the root of the project directory - (optional) Add
third_party.user.ymlto set platform-specific settings (don't forget to add it to.gitignore) - Use the module inside your
premake5.luafile:-
Add
acquire()call at the top of the file:local third_party = require "third_party/third_party" third_party.acquire()
acquire()accepts a path to a file (without extension) as an argument, similar torequire()in case you prefer for yourconfig.ymlfile to be named differently, or placed somewhere other than the roon of your project. Default value isthird_party, e.g.third_party.ymlin the same directory aspremake5.luais used as a config file. -
Add
third_party.depends(...)orthird_party.depends_on_everything()call inside project definition.
Note: one could add an alias to any function, for example:depends = third_party.depends depends_on_everything = third_party.depends_on_everything
-
- Enjoy!
The file is a dictionary with the structure of:
dependency_name:
- list
- of
- actions
second_dependency:
- second
- list
# ...-
github_release
Downloads an asset from a tagged github release.
Accepts parameters:- username of the repository
owner tagof the release- (optional) repository
name, if not presentdependency_nameis used instead - (optional) custom
filename, if not present,Source code (zip)is downloaded
- username of the repository
-
github_clone
Clones a detached head of the repository at specified tag or branch
Accepts parameters:owner, username of the repositoryownertagorbranchto clone. If both are present,branchis ignored.- (optional) repository
name, if not presentdependency_nameis used instead - (optional)
optionsto pass togit clonecommand, e.g.--recursive
-
downloadDownloads a single file using specified url. Acceps parameters:urladdress of the filefilenameto save the file as
-
cmake
Builds the project (usingcmake --build) and installs it (cmake 3.15+is required)
Acceptsdefaultor optional parameters:configis one ofrelease,debugordefault, wheredefaultbuilds both release and debug versionslog_location- a directory to place the file withstdoutoutput ofcmakecalls (default value isthird_party/log),stderris not affected.
And a set of
optionsparameters:optionsto pass tocmake .command, e.g.-G <generator-name>build_optionsto pass tocmake --build, e.g.-j [<jobs>]native_build_optionsto pass tocmake --buildafter--install_optionsto pass tocmake --installcommand, e.g.--component <comp>
As well as prefixes for them:
- configuration:
release_ordebug_(for example,release_install_optionsordebug_build_options) - target OS:
windows_,linux_,macosx_,aix_,bsd_,haiku_,solaris_,wii_orxbox360_(for examplewindows_native_build_optionsorlinux_options)
Any combination of these prefixes are acceptable, for example both
release_linux_optionsandlinux_release_optionsare equivalent and are concatenated together (both can even be used for the same action) -
install
Copies files to install location based on specified patterns
Accepts parameters, at least one of{include, source, lib}must be present:include- a pattern or a list of patterns to be copied to{install_dir}/include/**, default is{source_dir}/include/**source- a pattern or a list of patterns to be copied to{install_dir}/source/**, default is{source_dir}/source/**lib- a pattern or a list of patterns to be copied to{install_dir}/lib/**, default is{source_dir}/lib/**log_location- a directory where to place the file with output ofisntallcommand calls (default value isthird_party/log)configis one ofrelease,debugordefault, wheredefaultinstalls into both release and debug directories
Note, that
{source_dir}is implied and must not be explicitly added to patterns, e.g.{source_dir}/includes/my_include/single_file.hppis to be specified asincludes/my_include/single_file.hpp -
depend
Selects files to be used by the project to whendepends(...)ordepends_on_everything()is called.
Acceptsdefaultor optional parameters:include, a single pattern or a list of patterns to be added toincludedirsof the project, e.g.include/add/only/this/subdirectory/**. Default value isincludelib, a single pattern or a list of patterns to be added as input library dependencies, e.g.lib/link_only_this_one_file.*, orlib/link/everything/from/this/subdirectory/**. Default value islib/**files, a single pattern or a list of patterns to be added as source files to the project, e.g.source/**to add everything from the directory. Default value is{ "source/**", "include/**" }vpaths, adefaultor a dictionary wherelhsare virtual path pattern andrhs- real one, e.g.resource/text_files: **.txtwould consider all the*.txtfiles as part ofresource/text_filesvirtual directory. Default value is{ dependency_name/include: include/**, dependency_name/source: source/** }
-
globalSelects to be by the project to whendepends(...)ordepends_on_everything()is called.
The difference fromdependis thatglobaldoes not require any previous steps. This allows to simply link or add as include directory or even add a source file using its global path. This option is intended primarily to give an ability to use 'third_party' together with another dependency management system. Acceptsdefaultor optional parameters equivalent to adependaction.
The file is a dictionary with the structure of:
option: value
second_option: second_value
# ...verbose- iftrue, additional output is "thrown" intostdout.debug- same asverbose, if both are specified, the value is (verboseordebug), e.g. it'sfalseonly if both of them are set tofalse(or not specified)cmake- path to cmake, only needed ifcmakeis not present in thePATHvariable. It should not include filename itself. Only the directory.git- path to cmake, only needed ifgitis not present in thePATHvariable. It should not include filename itself. Only the directory.
local third_party = require "third_party/third_party"
third_party.acquire "third_party"
workspace "example_solution"
-- workspace settings
project "example_lib"
kind "StaticLib"
language "C++"
-- project settings
files {
"include/**"
"source/lib/**"
}
third_party.depends {
"lib_dependency_1_name",
"lib_dependency_2_name",
-- ...
"lib_dependency_N_name"
}
project "example_app"
kind "ConsoleApp"
language "C++"
-- project settings
files {
"include/**"
"source/app/**"
}
third_party.depends {
"app_dependency_1_name",
"app_dependency_2_name",
-- ...
"app_dependency_N_name"
}# cmake example
glfw:
- github_release:
owner: glfw
tag: "3.3.2"
file: glfw-3.3.2.zip
- cmake:
debug_options: >
-DUSE_MSVC_RUNTIME_LIBRARY_DLL=ON
linux_options: >
-G "Unix Makefiles"
- depend:
include: include
lib: lib/*
# example of adding source files to the project
lodepng:
- github_clone:
owner: Cvelth
branch: master
- install:
include: lodepng.h
source: lodepng.cpp
- depend:
include: default
files:
- include/lodepng.h
- source/lodepng.cpp
vpaths:
lodepng: "**"
# header only example
vkfw:
- github_clone:
owner: cvelth
tag: main
- install:
include: default
- depend:
include: default
# single header example
doctest:
- download:
url: https://raw.githubusercontent.com/onqtam/doctest/2.4.1/doctest/doctest.h
filename: doctest.h
- install:
include: doctest.h
- depend: default
# global example
vulkan:
- global:
include: %VULKAN_SDK%/Include
lib: %VULKAN_SDK%/Lib/vulkan-1verbose: true # default: false
cmake: /usr/bin/custom/path/to/cmake # default: ""
git: /usr/bin/custom/path/to/git # default: ""