对CLion使用本地Makefile而不是CMake [英] Using local makefile for CLion instead of CMake

查看:2076
本文介绍了对CLion使用本地Makefile而不是CMake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将CLion配置为使用本地makefile而不是CMake来编译代码?我似乎无法从构建选项中找到实现此目标的方法.

Is there a way to configure CLion to use a local makefile to compile code, rather than CMake? I can't seem to find the way to do it from the build options.

推荐答案

即使当前仅支持CMake,您也可以指示CMake使用自定义Makefile调用make.编辑CMakeLists.txt,添加以下两个命令之一:

Even though currently only CMake is supported, you can instruct CMake to call make with your custom Makefile. Edit your CMakeLists.txt adding one of these two commands:

  • add_custom_target
  • add_custom_command

当您告诉CLion运行程序时,它将尝试在PROJECT_BINARY_DIR指向的目录中查找与目标名称相同的可执行文件.因此,只要您的make生成CLion期望的文件,就不会有问题.

When you tell CLion to run your program, it will try to find an executable with the same name of the target in the directory pointed by PROJECT_BINARY_DIR. So as long as your make generates the file where CLion expects, there will be no problem.

这是一个有效的示例:

这是示例CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.4)
project(mytest)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_custom_target(mytest COMMAND make -C ${mytest_SOURCE_DIR}
                         CLION_EXE_DIR=${PROJECT_BINARY_DIR})

告诉make在CLion's目录中生成可执行文件

这是示例Makefile:

Tell make to generate the executable in CLion's directory

This is the sample Makefile:

all:
    echo Compiling $(CLION_EXE_DIR)/$@ ...
    g++ mytest.cpp -o $(CLION_EXE_DIR)/mytest

仅此而已,您可能还想更改程序的工作目录,以使其在从目录内部运行make时照常执行.对于此Run -> Edit Configurations ... -> mytest -> Working directory

That is all, you may also want to change your program's working directory so it executes as it is when you run make from inside your directory. For this edit: Run -> Edit Configurations ... -> mytest -> Working directory

这篇关于对CLion使用本地Makefile而不是CMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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