如何使用get_dotapp_dir? [英] How do I use get_dotapp_dir?

查看:111
本文介绍了如何使用get_dotapp_dir?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用get_dotapp_dir?

我正在使用cmake 3.6和Ninja生成器(而不是Xcode).

I'm using cmake 3.6 and the Ninja generator (so not Xcode).

例如,假设我有fred.c:

For example, suppose I have fred.c:

int main(void){return 0;}

还有CMakeLists.txt :( cmake版本号是我固定的东西)

And CMakeLists.txt: (the cmake version number is something I am stuck with)

cmake_minimum_required(VERSION 2.8.21.1)
include(BundleUtilities)
add_executable(fred MACOSX_BUNDLE fred.c)
set_target_properties(fred PROPERTIES BUNDLE TRUE)
get_dotapp_dir($<TARGET_FILE:fred> THING)
add_custom_command(TARGET fred POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo ${THING} VERBATIM)

我构建时的输出是/Users/worktom/tests/cmake_get_dotapp_dir/build/fred.app/Contents/MacOS/fred ...,这不是捆绑包文件夹!

The output when I build is /Users/worktom/tests/cmake_get_dotapp_dir/build/fred.app/Contents/MacOS/fred... which is not the bundle folder!

我有点这样,因为生成器表达式是在构建时求值的,而不是在cmake运行时求值的.但是然后...看起来似乎可以正常工作,因为目标文件的路径已经通过!这是怎么回事?这应该工作吗?我实际上应该何时/如何致电get_dotapp_dir?

I sort-of expected this, because generator expressions are evaluated at build time, and not when cmake is running. But then... it seems to be sort-of working, because the target file's path has come through! What's going on? Is this supposed to work? When/how am I actually supposed to call get_dotapp_dir?

(构建了包,我想将其他文件复制到其中,然后在每次构建时,我都想将结果复制到其他文件夹中,这些都与我正在构建的cmake项目无关.看起来就像我需要的那样,按照我的示例,该路径的格式可以传递给cmake -E.)

(Having built the bundle, I want to copy additional files into it, and then on every build I want to copy the result into additional folders, none of which are related to the cmake projects I'm building. So it looks like I need the path in a form that can be passed into cmake -E, as per my example.)

推荐答案

去年在第二个项目中遇到这个问题后,我得出的结论是,get_dotapp_dir如今已毫无用处,对于cmake 3+来说,这毫无意义,并且可能只是为了向后兼容.

After hitting this problem on a second project last year, I ended up concluding that get_dotapp_dir is just useless nowadays, makes little sense with cmake 3+, and is probably just something that's there for backwards compatibility.

如果您可以升级到cmake 3.9,则有一个新的生成器表达式仅显示故障单:相关的SO问题.

If you can upgrade to cmake 3.9, there's a new generator expression that looks just the ticket: $<TARGET_BUNDLE_DIR:>. Related SO question.

我还没有升级,最终我设法解决了这个问题.我的项目需要知道bundle文件夹,其原因有两个:

I haven't upgraded just yet, and I ended up managing to work around this. My project needed to know the bundle folder for two reasons:

  1. 在运行时加载的资产文件,需要包含在捆绑软件中.我为此所做的最终是让程序在运行时找到其EXE路径,并从相对于该路径的文件夹中加载资产.然后,cmake构建可以只使用$<TARGET_FILE_DIR:>来决定将文件放置在bundle文件夹中的什么位置,但这并不重要.

  1. Asset files that are loaded at runtime and need to be included in the bundle. What I did for this in the end was have the program find its EXE path at runtime, and load assets from folders relative to that path. Then the cmake build can just use $<TARGET_FILE_DIR:> to decide where to put the files - somewhere in the bundle folder, but it doesn't matter exactly where.

此行为也适用于Windows,因此不需要单独的代码路径.

This behaviour also makes sense for Windows, so no need for a separate code path.

回购链接,因为该项目是开源的:

Repo links, since this project is open source: copy files to places relative to EXE path, retrieve EXE path at runtime.

OS X用于加载图标的.icns文件必须放在Resources文件夹中.可以通过将文件包括在目标的源列表中,并适当地配置该文件的程序包位置属性来进行安排.

The .icns file that OS X uses to load the icons has to go in the Resources folder. This can be arranged by including the file in the target's sources list, and configuring that file's package location property appropriately.

target_sources(b2 PRIVATE b2.icns)
set_source_files_properties(b2.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)

可执行目标需要使用与set_target_properties(b2 PROPERTIES MACOSX_BUNDLE_ICON_FILE b2.icns)相似的方式正确设置其捆绑包图标文件.

The executable target needs to have its bundle icon file set up appropriately with something along the lines of set_target_properties(b2 PROPERTIES MACOSX_BUNDLE_ICON_FILE b2.icns).

同样,回购链接:制作东西OS X icns文件.

这篇关于如何使用get_dotapp_dir?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆