-
-
Notifications
You must be signed in to change notification settings - Fork 816
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
Add template configuration files and replace all variables before building #320
Closed
39 tasks done
Labels
Milestone
Comments
waruqi
changed the title
Add common configuration and template files in configuration and building stage
Add template configuration files and replace all variables before building
Feb 2, 2019
Examples-- set global config variables
set_configvar("VAR1", get_config("var1"))
set_configvar("VAR2", get_config("var2"))
target("test")
set_kind("binary")
add_files("main.c")
-- only set variable to test target
set_configvar("module", "test")
-- set config output directory
set_configdir("$(buildir)/config")
-- add config files
add_configfiles("config.h.in", {variables = {hello = "xmake"}, prefixdir = "header"})
add_configfiles("*.man", {copyonly = true})
-- search the generated config.h
add_includedirs("$(buildir)/config/header") config.h.in #define VAR1 "${VAR1}"
#define VAR2 "${VAR2}"
#define HELLO "${HELLO}" |
Examplesset_configvar("VAR", get_config("var"))
target("test")
set_kind("binary")
add_files("main.c")
add_configfiles("config.h.in", {pattern = "@(.-)@"})
add_includedirs("$(buildir)") config.h.in #define VAR "@VAR@" |
Pass boolean option status to the macro definitionsoption("foo")
set_default(true)
set_description("Enable Foo")
option_end()
if has_config("foo") then
set_configvar("FOO_ENABLE", 1) -- or pass true
set_configvar("FOO_STRING", "foo")
end config.h.in ${define FOO_ENABLE}
${define FOO_STRING} config.h #define FOO_ENABLE 1
#define FOO_STRING "foo" Or
|
Pass string option status to the macro definitionsoption("foo")
set_default("foo")
set_description("The Foo Info")
option_end()
if has_config("foo") then
set_configvar("FOO_STRING", get_config("foo"))
end config.h.in ${define FOO_STRING} config.h #define FOO_STRING "foo" Or
|
Attach option status and the macro definitions to targetoption("foo")
set_default(true)
set_description("Enable Foo")
set_configvar("FOO_ENABLE", 1) -- or pass true
set_configvar("FOO_STRING", "foo")
target("test")
add_configfiles("config.h.in")
-- if foo enabled -> add FOO_ENABLE and FOO_STRING definitions
add_options("foo") config.h.in ${define FOO_ENABLE}
${define FOO_STRING} config.h #define FOO_ENABLE 1
#define FOO_STRING "foo" Or
|
Uses the builtin version variablestarget("test")
set_version("1.6.3")
add_configfiles("config.h.in") config.h.in #define CONFIG_VERSION "${VERSION}"
#define CONFIG_VERSION_MAJOR ${VERSION_MAJOR}
#define CONFIG_VERSION_MINOR ${VERSION_MINOR}
#define CONFIG_VERSION_ALTER ${VERSION_ALTER}
#define CONFIG_VERSION_BUILD ${VERSION_BUILD} config.h #define CONFIG_VERSION "1.6.3"
#define CONFIG_VERSION_MAJOR 1
#define CONFIG_VERSION_MINOR 6
#define CONFIG_VERSION_ALTER 3
#define CONFIG_VERSION_BUILD 201902031401 |
13 tasks
Add default variables config.h.in HAVE_SSE2 equ ${default VAR_HAVE_SSE2 0} default config.h HAVE_SSE2 equ 0 After config.h HAVE_SSE2 equ 1 |
#342 Add some builtin help functions for |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
References
Add configuration files and modify output path
Generate configuation file before building when running
$ xmake config
set_configdir("$(buildir)/config")
$(buildir)
add_configfiles("src/config.h.in")
buildir/config/config.h
add_configfiles("src/*.h.in", {prefixdir = "subdir"})
buildir/config/subdir/*.h
add_configfiles("src/config.h")
buildir/config/config.h
add_configfiles("src/config.h", {filename = "myconfig.h"})
buildir/config/myconfig.h
add_configfiles("src/(tbox/config.h)")
buildir/config/tbox/config.h
Add configuration files and pass arguments
add_configfiles("src/config.h", {onlycopy = true})
buildir/config/config.h
, without replacing any variable references or other contentadd_configfiles("src/config.h", {pattern = "@(.-)@"})
%${(.-)}
add_configfiles("src/config.h", {variables = {var1 = "xxx", var2 = "yyy"}})
${var1}
,${var2}
Pass macro definitions and option status
set_configvar("VAR", 1)
${VAR}
=> 1${define VAR}
=>#define VAR 1
or#undef VAR
${default VAR 0}
=>1
or0
Deprecated Apis:
Set the template variables for configuration file.
set_configvar("var1", "xxx")
set_configvar("zzz.var3", "yyy")
Builtin variables
${VERSION}
-> 1.6.3${VERSION_MAJOR}
-> 1${VERSION_MINOR}
-> 6${VERSION_ALTER}
-> 3${VERSION_BUILD}
->set_version("1.6.3", {build = "%Y%m%d%H%M"})
-> 201902031421${PLAT}
and${plat}
-> MACOS and macosx${ARCH}
and${arch}
-> ARM and arm${MODE}
and${mode}
-> DEBUG/RELEASE and debug/release${DEBUG}
and${debug}
-> 1 or 0${OS}
and${os}
-> IOS or iosFeatures
The text was updated successfully, but these errors were encountered: