Skip to content
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 has_cflags, has_xxx for target #3522

Closed
waruqi opened this issue Mar 17, 2023 · 1 comment
Closed

Add has_cflags, has_xxx for target #3522

waruqi opened this issue Mar 17, 2023 · 1 comment

Comments

@waruqi
Copy link
Member

waruqi commented Mar 17, 2023

has_cfuncs/has_cxxfuncs for target

We can check c/c++ functions in target from packages

add_requires("zlib")
target("test")
    set_kind("binary")
    add_files("src/*.c")
    add_packages("zlib")
    on_config(function (target)
        if target:has_cfuncs("inflate", {includes = "zlib.h"}) then
            target:add("defines", "HAVE_INFLATE")
        end
    end)

has_cincludes/has_cxxincludes for target

We can check c/c++ includes in target from packages

add_requires("zlib")
target("test")
    set_kind("binary")
    add_files("src/*.c")
    add_packages("zlib")
    on_config(function (target)
        if target:has_cincludes("zlib.h") then
            target:add("defines", "HAVE_ZLIB_H")
        end
    end)

has_ctypes/has_cxxtypes for target

We can check c/c++ types in target from packages

add_requires("zlib")
target("test")
    set_kind("binary")
    add_files("src/*.c")
    add_packages("zlib")
    on_config(function (target)
        if target:has_ctypes("z_stream", {includes = "zlib.h"}) then
            target:add("defines", "HAVE_ZSTEAM_T")
        end
    end)

has_csnippets/has_cxxsnippets for target

We can check c/c++ snippets in target from packages

add_requires("libtins")
target("test")
    set_kind("binary")
    add_files("src/*.cpp")
    add_packages("libtins")
    on_config(function (target)
        local has_snippet = target:check_cxxsnippets({test = [[
            #include <string>
            using namespace Tins;
            void test() {
                std::string name = NetworkInterface::default_interface().name();
                printf("%s\n", name.c_str());
            }
        ]]}, {configs = {languages = "c++11"}, includes = {"tins/tins.h"}}))
        if has_snippet then
            target:add("defines", "HAS_XXX")
        end
    end)

has_cflags/has_cxxflags for target/package

target("test")
    set_kind("binary")
    add_files("src/*.cpp")
    on_config(function (target)
        if target:has_cxxflags("-fPIC") then
            target:add("defines", "HAS_PIC")
        end
    end)

has_features for target/package

target("test")
    set_kind("binary")
    add_files("src/*.cpp")
    on_config(function (target)
        if target:has_features("c_static_assert") then
            target:add("defines", "HAS_STATIC_ASSERT")
        end
        if target:has_features("cxx_constexpr") then
            target:add("defines", "HAS_CXX_CONSTEXPR")
        end
    end)

Now has_features/has_cflags/has_cxxflags are also available in package. We can use it in on_test/on_install

@waruqi waruqi added this to the v2.7.8 milestone Mar 17, 2023
@waruqi
Copy link
Member Author

waruqi commented Mar 17, 2023

xmake update -s github:xmake-io/xmake#hasxxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant