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.yml
config file to the root of the project directory - (optional) Add
third_party.user.yml
to set platform-specific settings (don't forget to add it to.gitignore
) - Use the module inside your
premake5.lua
file:-
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.yml
file to be named differently, or placed somewhere other than the roon of your project. Default value isthird_party
, e.g.third_party.yml
in the same directory aspremake5.lua
is 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
tag
of the release- (optional) repository
name
, if not presentdependency_name
is used instead - (optional) custom
file
name, 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 repositoryowner
tag
orbranch
to clone. If both are present,branch
is ignored.- (optional) repository
name
, if not presentdependency_name
is used instead - (optional)
options
to pass togit clone
command, e.g.--recursive
-
download
Downloads a single file using specified url. Acceps parameters:url
address of the filefilename
to save the file as
-
cmake
Builds the project (usingcmake --build
) and installs it (cmake 3.15+
is required)
Acceptsdefault
or optional parameters:config
is one ofrelease
,debug
ordefault
, wheredefault
builds both release and debug versionslog_location
- a directory to place the file withstdout
output ofcmake
calls (default value isthird_party/log
),stderr
is not affected.
And a set of
options
parameters:options
to pass tocmake .
command, e.g.-G <generator-name>
build_options
to pass tocmake --build
, e.g.-j [<jobs>]
native_build_options
to pass tocmake --build
after--
install_options
to pass tocmake --install
command, e.g.--component <comp>
As well as prefixes for them:
- configuration:
release_
ordebug_
(for example,release_install_options
ordebug_build_options
) - target OS:
windows_
,linux_
,macosx_
,aix_
,bsd_
,haiku_
,solaris_
,wii_
orxbox360_
(for examplewindows_native_build_options
orlinux_options
)
Any combination of these prefixes are acceptable, for example both
release_linux_options
andlinux_release_options
are 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 ofisntall
command calls (default value isthird_party/log
)config
is one ofrelease
,debug
ordefault
, wheredefault
installs 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.hpp
is 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.
Acceptsdefault
or optional parameters:include
, a single pattern or a list of patterns to be added toincludedirs
of the project, e.g.include/add/only/this/subdirectory/**
. Default value isinclude
lib
, 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
, adefault
or a dictionary wherelhs
are virtual path pattern andrhs
- real one, e.g.resource/text_files: **.txt
would consider all the*.txt
files as part ofresource/text_files
virtual directory. Default value is{ dependency_name/include: include/**, dependency_name/source: source/** }
-
global
Selects to be by the project to whendepends(...)
ordepends_on_everything()
is called.
The difference fromdepend
is thatglobal
does 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. Acceptsdefault
or optional parameters equivalent to adepend
action.
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 (verbose
ordebug
), e.g. it'sfalse
only if both of them are set tofalse
(or not specified)cmake
- path to cmake, only needed ifcmake
is not present in thePATH
variable. It should not include filename itself. Only the directory.git
- path to cmake, only needed ifgit
is not present in thePATH
variable. 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-1
verbose: true # default: false
cmake: /usr/bin/custom/path/to/cmake # default: ""
git: /usr/bin/custom/path/to/git # default: ""