使用 CMake 和 Xcode:修改 CMakeLists.txt 时保留项目更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3264028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Working with CMake and Xcode: keep project changes when CMakeLists.txt is modified
提问by YuppieNetworking
First of all, I've never developed with Xcode. I have a project that has been developed by me under a certain environment (Linux and emacs) and now some colleagues that use a different environment will work with me. This is a C++ project that uses CMake.
首先,我从来没有用 Xcode 开发过。我有一个项目是我自己在某种环境(Linux和emacs)下开发的,现在一些使用不同环境的同事会和我一起工作。这是一个使用 CMake 的 C++ 项目。
Long story short:
长话短说:
- I use Linux/emacs. Other developers use mac/Xcode.
- I use the GNU Makefiles generator. They use Xcode generator.
- Everything seemed to work ok.
- 我使用 Linux/emacs。其他开发人员使用 mac/Xcode。
- 我使用 GNU Makefiles 生成器。他们使用 Xcode 生成器。
- 一切似乎都正常。
The problem
问题
Xcode developers will use the executable that appears under the Executableslist of the Group & Fileswindow of Xcode. They will configure it by double-clicking and add their tweaks (configuring debugging directories, setting environment variables, but more importantly, setting the arguments of the executable).
Xcode 开发人员将使用出现在Xcode的Group & Files窗口的Executables列表下的可执行文件。他们将通过双击来配置它并添加他们的调整(配置调试目录,设置环境变量,但更重要的是,设置可执行文件的参数)。
When a developer (me) changes the CMakeLists.txt
(namely to add a new source file), the XCode developers are forced to re-generate their project and they loseall the configuration mentioned above.
当开发人员(我)更改CMakeLists.txt
(即添加新的源文件)时,XCode 开发人员将被迫重新生成他们的项目,并且他们会丢失上述所有配置。
Question:Is there a way to avoid this?
问题:有没有办法避免这种情况?
If each Xcode developer constantly loses that configuration I would certainly be the only one using CMake. :(
如果每个 Xcode 开发人员不断丢失该配置,我肯定会是唯一一个使用 CMake 的人。:(
Thanks for your help!
谢谢你的帮助!
回答by Daniel Blezek
I think you are going to lose this one. Xcode stores all the project definitions in a file called Foo.xcodeproj/project.pbxproj. When one of your Mac developers changes a flag or setting, it's recorded in the project.pbxproj file. When you change your CMakeLists.txt file, CMake triggers a rebuild of project.pbxproj, wiping out all the Mac developer's changes. Xcode was not designed with CMake in mind, and they two work only so well together.
我想你会失去这个。Xcode 将所有项目定义存储在一个名为 Foo.xcodeproj/project.pbxproj 的文件中。当您的 Mac 开发人员之一更改标志或设置时,它会记录在 project.pbxproj 文件中。当您更改 CMakeLists.txt 文件时,CMake 会触发 project.pbxproj 的重建,从而清除 Mac 开发人员的所有更改。Xcode 的设计并没有考虑到 CMake,它们两个一起工作得很好。
One possible solution (which isn't the greatest for the Mac developers) is to use CMake to generate makefiles. They would need to write a few custom commands in Xcode which invoke CMake/Make to build the executables, but they would be able to pass arguments into CMake to control the build process. The executables would be defined separately to Xcode, and CMake would only wipe out the Makefiles. This might be a way to keep everyone happy.
一种可能的解决方案(对于 Mac 开发人员来说不是最好的)是使用 CMake 生成 makefile。他们需要在 Xcode 中编写一些自定义命令来调用 CMake/Make 来构建可执行文件,但他们将能够将参数传递给 CMake 以控制构建过程。可执行文件将单独定义到 Xcode,而 CMake 只会清除 Makefile。这可能是让每个人都开心的一种方式。
The CMake folks have not given Xcode the attention it deserves, IMHO. But this limitation is inherent in Xcode's architecture, and will be a tough nut.
恕我直言,CMake 人员并没有给予 Xcode 应有的关注。但是这种限制是 Xcode 架构中固有的,并且将是一个棘手的问题。
Hope this helps,
-dan
希望这会
有所帮助,-dan
Edit:
编辑:
Your Xcode developers have some limited ability to use "User-Defined Settings". I don't know to how to use these (I'm an emacs/make-sort of guy), but perhaps they could use these to override CMake's settings.
您的 Xcode 开发人员使用“用户定义的设置”的能力有限。我不知道如何使用这些(我是一个 emacs/make 类型的人),但也许他们可以使用这些来覆盖 CMake 的设置。
回答by Rudi
You can add a target which runs the program by add_custom_target(foobar COMMAND foo --bar DEPENDS foo)
. You can also call a script instead of the program, where it is easy to set environment variables (I use this setup under Win32 to tweak paths in VC). This script could also be a template in the VCS, so each developer has an own version of the script with the actual command line parameters.
您可以添加一个运行程序的目标add_custom_target(foobar COMMAND foo --bar DEPENDS foo)
。您还可以调用脚本而不是程序,这样可以轻松设置环境变量(我在 Win32 下使用此设置来调整 VC 中的路径)。此脚本也可以是 VCS 中的模板,因此每个开发人员都有自己的带有实际命令行参数的脚本版本。