-
-
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 some builtin help functions for includes()
, e.g. check_xxx
#342
Labels
Milestone
Comments
ExamplesCheck links, ctype, includes and features and write macro definitions to the config.h file. includes("check_links.lua")
includes("check_ctypes.lua")
includes("check_cfuncs.lua")
includes("check_features.lua")
includes("check_csnippets.lua")
includes("check_cincludes.lua")
target("test")
set_kind("binary")
add_files("*.c")
add_configfiles("config.h.in")
configvar_check_ctypes("HAS_WCHAR", "wchar_t")
configvar_check_cincludes("HAS_STRING_H", "string.h")
configvar_check_cincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"})
configvar_check_ctypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"})
configvar_check_links("HAS_PTHREAD", {"pthread", "m", "dl"})
configvar_check_csnippets("HAS_STATIC_ASSERT", "_Static_assert(1, \"\");")
configvar_check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}})
configvar_check_features("HAS_CONSTEXPR", "cxx_constexpr")
configvar_check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {languages = "c++11"}) config.h.in ${define HAS_STRING_H}
${define HAS_STRING_AND_STDIO_H}
${define HAS_WCHAR}
${define HAS_WCHAR_AND_FLOAT}
${define HAS_PTHREAD}
${define HAS_STATIC_ASSERT}
${define HAS_SETJMP}
${define HAS_CONSTEXPR}
${define HAS_CONSEXPR_AND_STATIC_ASSERT} config.h /* #undef HAS_STRING_H */
#define HAS_STRING_AND_STDIO_H 1
/* #undef HAS_WCHAR */
/* #undef HAS_WCHAR_AND_FLOAT */
#define HAS_PTHREAD 1
#define HAS_STATIC_ASSERT 1
#define HAS_SETJMP 1
/* #undef HAS_CONSTEXPR */
#define HAS_CONSEXPR_AND_STATIC_ASSERT 1 |
ExamplesCheck links, ctype, includes and features and add macro definitions to the given target. includes("check_links.lua")
includes("check_ctypes.lua")
includes("check_cfuncs.lua")
includes("check_features.lua")
includes("check_csnippets.lua")
includes("check_cincludes.lua")
target("test")
set_kind("binary")
add_files("*.c")
check_ctypes("HAS_WCHAR", "wchar_t")
check_cincludes("HAS_STRING_H", "string.h")
check_cincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"})
check_ctypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"})
check_links("HAS_PTHREAD", {"pthread", "m", "dl"})
check_csnippets("HAS_STATIC_ASSERT", "_Static_assert(1, \"\");")
check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}})
check_features("HAS_CONSTEXPR", "cxx_constexpr")
check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {languages = "c++11"}) /usr/local/bin/ccache xcrun -sdk macosx clang -c -DHAS_STRING_H -DHAS_STATIC_ASSERT -DHAS_CONSTEXPR -Qunused-arguments -arch
x86_64 -fpascal-strings -fmessage-length=0 -isysroot /Applications/Xcode.app/Contents/Dev
eloper/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -o build/.objs/test/macos
x/x86_64/release/./main.c.o main.c |
Implemention-- check c funcs and add macro definition
--
-- the function syntax
-- - sigsetjmp
-- - sigsetjmp((void*)0, 0)
-- - sigsetjmp{sigsetjmp((void*)0, 0);}
-- - sigsetjmp{int a = 0; sigsetjmp((void*)a, a);}
--
-- e.g.
--
-- check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}})
-- check_cfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"})
--
function check_cfuncs(definition, funcs, opt)
opt = opt or {}
option(opt.name or definition)
add_cfuncs(funcs)
add_defines(definition)
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cflags then
add_cxflags(opt.cxflags)
end
option_end()
add_options(opt.name or definition)
end
-- check c funcs and add macro definition to the configuration files
--
-- e.g.
--
-- configvar_check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}})
-- configvar_check_cfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"})
--
function configvar_check_cfuncs(definition, funcs, opt)
opt = opt or {}
option(opt.name or definition)
add_cfuncs(funcs)
set_configvar(definition, 1)
if opt.links then
add_links(opt.links)
end
if opt.includes then
add_cincludes(opt.includes)
end
if opt.languages then
set_languages(opt.languages)
end
if opt.cflags then
add_cflags(opt.cflags)
end
if opt.cxflags then
add_cxflags(opt.cxflags)
end
option_end()
add_options(opt.name or definition)
end |
Closed
Set the custom alias: configvar_check_cincludes("HAS_STRING_H", "string.h", {name = "string_h"}) show: checking string_h ... |
waruqi
changed the title
Add some builtin help functions for
Add some builtin help functions for Feb 17, 2019
includes()
includes()
, e.g. check_xxx
includes("check_cflags.lua")
includes("check_cxxflags.lua")
target("test")
check_cxxflags("HAS_SSE2", "-msse2")
configvar_check_cflags("HAS_SSE2", "-msse2") |
Custom variable value configvar_check_cflags("SSE=2", "-msse2") config.h.in #define SSE ${default SSE 0} config.h #define SSE 2
// #define SSE 0 |
includes("find_and_add_packages.lua")
target("test")
set_kind("binary")
add_files("src/*.c")
find_and_add_packages("brew::pcre2/libpcre2-8", "zlib") |
39 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add some builtin help functions to simplify checking code using
option("xx")
References
Roadmap
includes("xxx.lua")
The search pathes of including lua scripts
projectdir/xmake.lua
Search pathes
The text was updated successfully, but these errors were encountered: