最近,我已经从CMake变成了Premake (v5.0.0-alpha8 8),我不太确定如何在预制作中实现以下目标。
我想包含一些依赖项,所以在CMake中我可以这样做:
target_link_libraries(${PROJECT_NAME}
${YALLA_ABS_PLATFORM}
${YALLA_LIBRARY})上面的代码将将这些库(dir)的路径添加到编译器中的“附加包含目录”,并且它还将在链接器中添加一个条目(lib)到“附加依赖项”,因此除了调用target_link_libraries之外,我不需要做任何特殊的事情。
所以我希望当我在预制片中做这样的事情时:
links {
YALLA_LIBRARY
}我也会得到同样的结果,但我没有。
我也尝试过使用libdirs,但它实际上不起作用,我的意思是我不能看到作为“附加包含目录”(/I)传递给编译器的库目录及其子目录,或者作为“附加依赖项”传递给链接器的Yalla.Library.lib。
这里是我使用的目录结构:
.
|-- src
| |-- launcher
| |-- library
| | `-- utils
| `-- platform
| |-- abstract
| `-- win32
`-- tests
`-- platform
`-- win32库 dir在Premake中定义如下:
project(YALLA_LIBRARY)
kind "SharedLib"
files {
"utils/string-converter.hpp",
"utils/string-converter.cpp",
"defines.hpp"
}平台 dir在预制件中定义如下:
project(YALLA_PLATFORM)
kind "SharedLib"
includedirs "abstract"
links {
YALLA_LIBRARY
}
if os.get() == "windows" then
include "win32"
else
return -- OS NOT SUPPORTED
endwin32 dir在预制作中定义如下:
files {
"event-loop.cpp",
"win32-exception.cpp",
"win32-exception.hpp",
"win32-window.cpp",
"win32-window.hpp",
"window.cpp"
}最后,在根 dir上,我有以下预制作文件:
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"由于缺乏经验,我可能误解了预制片的工作方式。
发布于 2016-03-27 14:16:45
我通过创建一个新的全局函数来解决这个问题,并将其命名为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如果将它们包含在目录结构中,它将失败,并告诉您“项目‘'Yalla.Platform’不存在”。
https://stackoverflow.com/questions/36234829
复制相似问题