diff options
| author | ruki <[email protected]> | 2024-08-21 11:15:47 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-08-21 11:15:47 +0800 |
| commit | 8fe3738c9b07f78b67ad4ed978bf6fedec2aeae2 (patch) | |
| tree | d5b6340434c5c00a7b0bc0fa7e849fdb5c78e45c | |
| parent | d3effb1bc2076932bbcc319a696be3f40b95d4b7 (diff) | |
| parent | 0f9a4976e600d9b13bc2484162e3b8c1aee07dfd (diff) | |
Merge pull request #5487 from xmake-io/cmake
improve flags support for cmake
| -rw-r--r-- | xmake/plugins/project/cmake/cmakelists.lua | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index eb20f6647..48a637a78 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -26,6 +26,7 @@ import("core.tool.compiler") import("core.base.semver") import("core.base.hashset") import("core.project.rule") +import("core.platform.platform") import("lib.detect.find_tool") import("private.utils.batchcmds") import("private.utils.rule_groups") @@ -298,15 +299,14 @@ function _get_flags_from_target(target, flagkind) end -- set compiler -function _set_target_compiler(cmakelists, target) - -- use custom toolchain? - if config.get("toolchain") or target:get("toolchains") then - local cc = target:tool("cc") +function _set_compiler(cmakelists) + if config.get("toolchain") then + local cc = platform.tool("cc") if cc then cc = path.unix(cc) cmakelists:print("set(CMAKE_C_COMPILER \"%s\")", cc) end - local cxx, cxx_name = target:tool("cxx") + local cxx, cxx_name = platform.tool("cxx") if cxx then if cxx_name == "clang" or cxx_name == "gcc" then local dir = path.directory(cxx) @@ -344,11 +344,7 @@ function _add_project(cmakelists, outputdir) -- set compilers, we need set it before project( LANGUAGES..) -- @see https://github.com/xmake-io/xmake/issues/5448 - for _, target in table.orderpairs(project.targets()) do - if target:is_binary() or target:is_static() or target:is_shared() then - _set_target_compiler(cmakelists, target) - end - end + _set_compiler(cmakelists) -- set project name local project_name = project.name() @@ -1030,8 +1026,8 @@ end -- add target link options function _add_target_link_options(cmakelists, target, outputdir) - local ldflags = _get_configs_from_target(target, "ldflags") - local shflags = _get_configs_from_target(target, "shflags") + local ldflags = _get_flags_from_target(target, "ldflags") + local shflags = _get_flags_from_target(target, "shflags") local toolnames = hashset.new() local function _add_target_link_options_for_linker(toolname) if #ldflags > 0 or #shflags > 0 then |
