diff options
| author | Mohammed <[email protected]> | 2023-07-13 08:11:33 -0500 |
|---|---|---|
| committer | Mohammed <[email protected]> | 2023-07-13 08:11:33 -0500 |
| commit | 60d6fe79e1c4d2def8e1561c142e427bd425e056 (patch) | |
| tree | 9f10a9d8a123cd90b516a09eacaf597e661c6443 | |
| parent | 7939d750e9dcd51b5bac3e4f4a7ead5a81b2bed0 (diff) | |
CMake only accepts the INTERFACE access type for including directories in header-only libraries
CMake only allows the use of the INTERFACE access type to include directories in header-only libraries.
However, Xmake generates a faulty CMakeLists.txt file when a header-only library has dependencies. This results in the following error message: "target_include_directories may only set INTERFACE properties on INTERFACE targets".
The root cause of this issue is that the include directory function is using a PRIVATE access type instead of INTERFACE. To address this problem, the proposed change checks whether the target is a header-only library and adjusts the access type accordingly.
| -rw-r--r-- | xmake/plugins/project/cmake/cmakelists.lua | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 5ee2da1b1..12cec5bcb 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -467,7 +467,8 @@ end function _add_target_include_directories(cmakelists, target, outputdir) local includedirs = _get_configs_from_target(target, "includedirs") if #includedirs > 0 then - cmakelists:print("target_include_directories(%s PRIVATE", target:name()) + local access_type = target:kind() == "headeronly" and "INTERFACE" or "PRIVATE" + cmakelists:print("target_include_directories(%s %s", target:name(), access_type) for _, includedir in ipairs(includedirs) do cmakelists:print(" " .. _get_relative_unix_path(includedir, outputdir)) end |
