简体   繁体   English

如何在cmake中为代码:: blocks编译SFML 2.2

[英]How to Compile sfml 2.2 in cmake for code::blocks

I am having a huge problem with the new sfml and have spent the day trying to figure it out. 我在使用新sfml时遇到了很大的问题,并花了整整一天的时间来弄清楚。 I have finally found I need to costume compile it with cmake. 我终于发现我需要使用cmake进行编译。 The big problem is is cmake keeps asking for CMakeLists.txt and its not there. 最大的问题是cmake一直在询问CMakeLists.txt,而该文件不在那儿。 Please help me I just want to start coding in sfml. 请帮助我,我只想开始在sfml中进行编码。 I am running windows 8.1 and if you need any more information just ask me and I will try to give you it. 我正在运行Windows 8.1,如果您需要更多信息,请问我,我会尽力给您。 If I am looking at the problem wrong can you please come up with a new solution. 如果我发现问题不对,您能提出一个新的解决方案吗?

In my opinion the easiest way to build SFML is to use the "MinGW Makefiles" CMake generator and the CMake GUI. 在我看来,构建SFML的最简单方法是使用“ MinGW Makefiles” CMake生成器和CMake GUI。 So here is a brief tutorial on how to build SFML that way. 因此,这是有关如何以这种方式构建SFML的简短教程。

Prepare your Development Environment 准备开发环境

If you do not have your MinGW compiler's bin directory in PATH , you can temporarily add it by opening a command prompt ( Windows Key + R and enter cmd + Enter ): 如果您的PATH没有MinGW编译器的bin目录,则可以通过打开命令提示符( Windows Key + R并输入cmd + Enter )来临时添加它:

set PATH=<path_to_your_mingw_compiler>\\bin;%PATH%

Next you can start the CMake GUI from the command prompt by typing cmake-gui . 接下来,您可以在命令提示符下键入cmake-gui来启动CMake GUI。 If CMake's bin directory hasn't been added to PATH , I highly recommend you do so in a similar fashion as mentioned above. 如果CMake的bin目录尚未添加到PATH ,我强烈建议您以与上述类似的方式添加。

设置PATH并打开CMake GUI

Then setup the path to SFML and a build path for, I usually just use the subdirectory build\\ . 然后设置SFML的路径和构建路径,我通常只使用子目录build\\

设置源和构建目录

Setup CMake 设置CMake

Then press the Configure button and pick the MinGW Makefiles generator. 然后按Configure按钮,然后选择MinGW Makefiles生成器。

Note: If you use MSYS you need to use the MSYS Makefiles generator instead. 注意:如果使用MSYS,则需要使用MSYS Makefiles生成器。

选择发电机

As a next step you can change the various CMake variables. 下一步,您可以更改各种CMake变量。 A full explanations of these options can be found in the official SFML CMake tutorial . 有关这些选项的完整说明,请参见官方SFML CMake教程 One of the important parts is to change the CMAKE_INSTALL_PREFIX , since you'll get permission issues with the default CMake value and you essentially really don't want your library files installed there. 重要的部分之一是更改CMAKE_INSTALL_PREFIX ,因为您将获得默认CMake值的权限问题,并且您实际上根本不希望在此处安装库文件。 Also don't pick the build directory, otherwise the install will end up messy. 也不要选择构建目录,否则安装将变得混乱。 I personally prefer to use the sub-directory /install . 我个人更喜欢使用子目录/install

安装路径选项

After you've changed everything you wanted to change you can click on Generate and you should get the two done-messages. 更改完所有要更改的内容后,可以单击“ Generate然后应该获得两个完成的消息。

成功配置

Actually Building SFML 实际上正在构建SFML

CMake merely generates makefiles and project files, as such SFML as a C++ library hasn't been built yet and thus we need to this next. CMake仅生成makefile和项目文件,因为尚未构建像C ++库这样的SFML,因此我们接下来需要这样做。 For that we switch back to the command prompt and change the directory to the build directory we've previously set in CMake. 为此,我们切换回命令提示符,并将目录更改为我们先前在CMake中设置的构建目录。

Since we want everything directly installed to the previously specified CMAKE_PREFIX_INSTALL directory, we'll now run the makefile's install target. 由于我们希望将所有内容直接安装到先前指定的CMAKE_PREFIX_INSTALL目录中,因此我们现在将运行makefile的install目标。 Additionally since we're most likely using a multi-core processor, we really want to get things building quickly and thus make use of the -jN flag, where N is an integer that specifies how many threads shall be used. 此外,由于我们最有可能使用多核处理器,因此我们确实希望快速构建事物,并因此使用-jN标志,其中N是一个整数,用于指定应使用的线程数。 Keep in mind that this can really freeze your system if you pick a number too high for your system. 请记住,如果您为系统选择的数字过高,这确实会冻结系统。 Enter the command mingw32-make install -jN as shown below. 输入命令mingw32-make install -jN ,如下所示。

Note: If you're using MSYS (or nuwen's MinGW compiler) you need to use make instead of mingw32-make . 注意:如果您使用的是MSYS(或nuwen的MinGW编译器),则需要使用make而不是mingw32-make

建立安装目标

Wait for the process to finish and check the install directory. 等待该过程完成,然后检查install目录。

Congratulations you have successfully built SFML! 恭喜,您已成功构建SFML!


Using Code::Blocks Instead 改用Code :: Blocks

If you really want a Code::Blocks project file, then you can repeat the first few steps from above, but instead of the MinGW Makefiles CMake generator pick the CodeBlocks - MinGW Makefiles . 如果您真的想要一个Code :: Blocks项目文件,则可以从上面重复前几步,但是可以用CodeBlocks - MinGW Makefiles代替MinGW Makefiles CMake生成器。

代码::块生成器

Adjust the settings as mentioned above, including CMAKE_INSTALL_PREFIX and press the Generate button. 调整上述设置,包括CMAKE_INSTALL_PREFIX ,然后按“ Generate按钮。 After everything has been generated, you can go and open up the Code::Blocks project file in the build directory. 生成所有内容后,您可以在build目录中打开Code :: Blocks项目文件。

代码::阻止项目文件

In Code::Blocks you can then easily pick your preferred target ( install is recommended) and click on the build button. 然后,在Code :: Blocks中,您可以轻松选择首选目标(建议install ),然后单击“生成”按钮。

代码::块目标

Wait for the process to finish and check the install directory. 等待该过程完成,然后检查install目录。

Congratulations you have successfully built SFML! 恭喜,您已成功构建SFML!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM