老makefile文件转换为CMake的 [英] Converting old makefile to CMake

查看:3987
本文介绍了老makefile文件转换为CMake的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的旧的makefile code转换为CMake的。你可以帮我吗?这是我目前被困的部分。我不知道如何把这些参数传递到编译器。

I'm trying to convert my old makefile code to CMake. Can you help me? This is the part where I'm currently stuck. I don't know how to pass these arguments to the compiler.

COMPILE_FLAGS = -c -m32 -O3 -fPIC -w -DSOMETHING -Wall -I src/sdk/core

ifdef STATIC
    OUTFILE = "bin/test_static.so"
    COMPILE_FLAGS_2 = ./lib/ABC.a
else
    OUTFILE = "bin/test.so"
    COMPILE_FLAGS_2 = -L/usr/lib/mysql -lABC
endif

all:
    g++ $(COMPILE_FLAGS) src/sdk/*.cpp
    g++ $(COMPILE_FLAGS) src/*.cpp
    g++ -fshort-wchar -shared -o $(OUTFILE) *.o $(COMPILE_FLAGS_2)
    rm -f *.o

感谢您!

推荐答案

让我们尝试映射的Makefile 语法 CMake的

COMPILE_FLAGS = -c -m32 -O3 -fPIC -w -DSOMETHING -Wall -I src/sdk/core

本声明直接映射到:

SET( COMPILE_FLAGS "-c -m32 -O3 -fPIC -w -DSOMETHING -Wall" )
INCLUDE_DIRECTORIES( src/sdk/core )

一个条件类型:

ifdef STATIC
  # Do something
else
  # Do something else
endif

被翻译在CMake的是这样的:

is translated in CMake in this way:

OPTION(STATIC "Brief description" ON)
IF( STATIC )
  # Do something
ELSE()
  # Do something else
ENDIF()

要修改默认的编译标志,你可以设置变量 CMAKE_< LANG> _FLAGS_RELEASE CMAKE_< LANG> _FLAGS_DEBUG 等,恰如其分。

To modify the default compilation flags you can set the variables CMAKE_<LANG>_FLAGS_RELEASE, CMAKE_<LANG>_FLAGS_DEBUG, etc. , appropriately.

最后一个可执行文件的编制要求您使用 ADD_EXECUTABLE 命令,它在许多CMake的教程解释。

Finally the compilation of an executable requires you to use the ADD_EXECUTABLE command, which is explained in many CMake tutorials.

在我建议你参考更多详细信息,在线文档,因为它是任何情况下,相当的解释和完整。

In any case I suggest you to refer to the online documentation for further details, as it is quite explanatory and complete.

这篇关于老makefile文件转换为CMake的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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