Premake 不获取依赖项
Premake doesn't picking up dependencies
最近我已经从 CMake 更改为 Premake (v5.0.0-alpha8),我不太确定如何在 Premake 中实现以下目标。
我想包含一些依赖项,所以在 CMake 中我可以这样做:
target_link_libraries(${PROJECT_NAME}
${YALLA_ABS_PLATFORM}
${YALLA_LIBRARY})
以上将在编译器中将这些库的路径 (dir) 添加到 "Additional Include Directories" 并且还将在链接器中将条目 (lib) 添加到 "Additional Dependencies" 所以我不除了调用 target_link_libraries
.
之外还需要做任何特别的事情
所以我预计当我在 Premake 中做这样的事情时:
links {
YALLA_LIBRARY
}
我会得到相同的结果,但我没有。
我也尝试过使用 libdirs
但它实际上 不起作用 ,我的意思是我看不到库目录及其子目录传递给编译器作为 "Additional Include Directories" (/I) 或 Yalla.Library.lib 传递给链接器作为 "Additional Dependencies".
这是我使用的目录结构:
.
|-- src
| |-- launcher
| |-- library
| | `-- utils
| `-- platform
| |-- abstract
| `-- win32
`-- tests
`-- platform
`-- win32
library目录在Premake中定义如下:
project(YALLA_LIBRARY)
kind "SharedLib"
files {
"utils/string-converter.hpp",
"utils/string-converter.cpp",
"defines.hpp"
}
platform 目录在 Premake 中定义如下:
project(YALLA_PLATFORM)
kind "SharedLib"
includedirs "abstract"
links {
YALLA_LIBRARY
}
if os.get() == "windows" then
include "win32"
else
return -- OS NOT SUPPORTED
end
win32目录在Premake中定义如下:
files {
"event-loop.cpp",
"win32-exception.cpp",
"win32-exception.hpp",
"win32-window.cpp",
"win32-window.hpp",
"window.cpp"
}
最后在 root 目录中,我有以下 Premake 文件:
PROJECT_NAME = "Yalla"
-- Sets global constants that represents the projects' names
YALLA_LAUNCHER = PROJECT_NAME .. ".Launcher"
YALLA_LIBRARY = PROJECT_NAME .. ".Library"
YALLA_ABS_PLATFORM = PROJECT_NAME .. ".AbstractPlatform"
YALLA_PLATFORM = PROJECT_NAME .. ".Platform"
workspace(PROJECT_NAME)
configurations { "Release", "Debug" }
flags { "Unicode" }
startproject ( YALLA_LAUNCHER )
location ( "../lua_build" )
include "src/launcher"
include "src/library"
include "src/platform"
由于缺乏经验,我可能误解了 Premake 的工作原理。
我通过创建一个新的全局函数并将其命名为includedeps
来解决它。
function includedeps(workspace, ...)
local workspace = premake.global.getWorkspace(workspace)
local args = { ... }
local args_count = select("#", ...)
local func = select(args_count, ...)
if type(func) == "function" then
args_count = args_count - 1
args = table.remove(args, args_count)
else
func = nil
end
for i = 1, args_count do
local projectName = select(i, ...)
local project = premake.workspace.findproject(workspace, projectName)
if project then
local topIncludeDir, dirs = path.getdirectory(project.script)
if func then
dirs = func(topIncludeDir)
else
dirs = os.matchdirs(topIncludeDir .. "/**")
table.insert(dirs, topIncludeDir)
end
includedirs(dirs)
if premake.project.iscpp(project) then
libdirs(dirs)
end
links(args)
else
error(string.format("project '%s' does not exist.", projectName), 3)
end
end
end
用法:
includedeps(PROJECT_NAME, YALLA_LIBRARY)
或
includedeps(PROJECT_NAME, YALLA_PLATFORM, function(topIncludeDir)
return { path.join(topIncludeDir, "win32") }
end)
更新:
为了正常工作你需要确保当你include
依赖时,它们是按照依赖顺序而不是目录顺序包含的结构。
因此,例如,如果我有以下依赖关系图 launcher --> platform --> library
,那么我必须按以下顺序 include
它们。
include "src/library"
include "src/platform"
include "src/launcher"
相对于我的目录结构如下:
src/launcher
src/library
src/platform
如果您按目录结构包含它们,它将失败并告诉您 "The project 'Yalla.Platform' does not exist."
最近我已经从 CMake 更改为 Premake (v5.0.0-alpha8),我不太确定如何在 Premake 中实现以下目标。
我想包含一些依赖项,所以在 CMake 中我可以这样做:
target_link_libraries(${PROJECT_NAME}
${YALLA_ABS_PLATFORM}
${YALLA_LIBRARY})
以上将在编译器中将这些库的路径 (dir) 添加到 "Additional Include Directories" 并且还将在链接器中将条目 (lib) 添加到 "Additional Dependencies" 所以我不除了调用 target_link_libraries
.
所以我预计当我在 Premake 中做这样的事情时:
links {
YALLA_LIBRARY
}
我会得到相同的结果,但我没有。
我也尝试过使用 libdirs
但它实际上 不起作用 ,我的意思是我看不到库目录及其子目录传递给编译器作为 "Additional Include Directories" (/I) 或 Yalla.Library.lib 传递给链接器作为 "Additional Dependencies".
这是我使用的目录结构:
.
|-- src
| |-- launcher
| |-- library
| | `-- utils
| `-- platform
| |-- abstract
| `-- win32
`-- tests
`-- platform
`-- win32
library目录在Premake中定义如下:
project(YALLA_LIBRARY)
kind "SharedLib"
files {
"utils/string-converter.hpp",
"utils/string-converter.cpp",
"defines.hpp"
}
platform 目录在 Premake 中定义如下:
project(YALLA_PLATFORM)
kind "SharedLib"
includedirs "abstract"
links {
YALLA_LIBRARY
}
if os.get() == "windows" then
include "win32"
else
return -- OS NOT SUPPORTED
end
win32目录在Premake中定义如下:
files {
"event-loop.cpp",
"win32-exception.cpp",
"win32-exception.hpp",
"win32-window.cpp",
"win32-window.hpp",
"window.cpp"
}
最后在 root 目录中,我有以下 Premake 文件:
PROJECT_NAME = "Yalla"
-- Sets global constants that represents the projects' names
YALLA_LAUNCHER = PROJECT_NAME .. ".Launcher"
YALLA_LIBRARY = PROJECT_NAME .. ".Library"
YALLA_ABS_PLATFORM = PROJECT_NAME .. ".AbstractPlatform"
YALLA_PLATFORM = PROJECT_NAME .. ".Platform"
workspace(PROJECT_NAME)
configurations { "Release", "Debug" }
flags { "Unicode" }
startproject ( YALLA_LAUNCHER )
location ( "../lua_build" )
include "src/launcher"
include "src/library"
include "src/platform"
由于缺乏经验,我可能误解了 Premake 的工作原理。
我通过创建一个新的全局函数并将其命名为includedeps
来解决它。
function includedeps(workspace, ...)
local workspace = premake.global.getWorkspace(workspace)
local args = { ... }
local args_count = select("#", ...)
local func = select(args_count, ...)
if type(func) == "function" then
args_count = args_count - 1
args = table.remove(args, args_count)
else
func = nil
end
for i = 1, args_count do
local projectName = select(i, ...)
local project = premake.workspace.findproject(workspace, projectName)
if project then
local topIncludeDir, dirs = path.getdirectory(project.script)
if func then
dirs = func(topIncludeDir)
else
dirs = os.matchdirs(topIncludeDir .. "/**")
table.insert(dirs, topIncludeDir)
end
includedirs(dirs)
if premake.project.iscpp(project) then
libdirs(dirs)
end
links(args)
else
error(string.format("project '%s' does not exist.", projectName), 3)
end
end
end
用法:
includedeps(PROJECT_NAME, YALLA_LIBRARY)
或
includedeps(PROJECT_NAME, YALLA_PLATFORM, function(topIncludeDir)
return { path.join(topIncludeDir, "win32") }
end)
更新:
为了正常工作你需要确保当你include
依赖时,它们是按照依赖顺序而不是目录顺序包含的结构。
因此,例如,如果我有以下依赖关系图 launcher --> platform --> library
,那么我必须按以下顺序 include
它们。
include "src/library"
include "src/platform"
include "src/launcher"
相对于我的目录结构如下:
src/launcher
src/library
src/platform
如果您按目录结构包含它们,它将失败并告诉您 "The project 'Yalla.Platform' does not exist."