Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

linux - CMAKE auto header file dependency

Question is similar to this question

Handling header files dependencies with cmake

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

main.h contents are

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

main.c contents are

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

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

and CMakeLists.txt

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

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

cmake_minimum_required(VERSION 2.8)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...