CMAKE自动头文件依赖 [英] CMAKE auto header file dependency

查看:426
本文介绍了CMAKE自动头文件依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题类似于此问题

使用cmake处理头文件依赖关系

我有一个示例程序dir有main.c main.h和CMakeLists.txt

I have sample program dir having main.c main.h and CMakeLists.txt

main.h内容是

#ifndef MAIN_H
#define MAIN_H
int t=3;
int y=2;
#endif

main.c内容为

#include <main.h>
#include<stdio.h>
int main(){

  printf("%d apple",t);
}

和CMakeLists.txt

and CMakeLists.txt

PROJECT( test )
AUX_SOURCE_DIRECTORY(. test_SRCS)
include_directories(.)
ADD_EXECUTABLE (main ${test_SRCS})

但是cmake不会在头文件修改时重建main.c。
我想让它自动生成头文件依赖。
是否可以使用cmake?

but cmake is not rebuilding main.c on modification of header file. I want it to auto-generate header file dependency. Is it possible using cmake ?

如果没有任何其他工具可以做到这一点?

if not is there any other tool which can do that ?

推荐答案

正如我在评论中提到的,我已经尝试了你的例子,事情工作正常:if main.h main.c 会被重新编译。

As mentioned in my comment, I have tried out your example and things were working fine: if main.h was modified then main.c would be recompiled.

我安装CMake(2.8.0版) / p>

My installation of CMake (version 2.8.0) told me to add

cmake_minimum_required(VERSION 2.8)

CMakeLists.txt 文件,但这是我需要的所有调整。

to the CMakeLists.txt file, but that is all of the adjustments I needed.

这篇关于CMAKE自动头文件依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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