[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

CMake зависимости



    Добрый...

Прошу совета у знатоков cmake.

Хочу, чтобы cmake корректно обрабатывал зависимости.

Если в C-файле делается include файлов с одинаковыми именами,
то в depends попадает только один из файлов.
И редактирование второго h-файла не приводит к пересборке C-файла.

Например,

 % cat dir1/file1.c
#include <h1.h>
#include "h1.h"

int main()
{
    printf("%s\n", H);
    printf("%s\n", G);

    return 0;
}

Собирается всё верно (т.е. с ключом -I для gcc)

...
 [100%] Building C object dir1/CMakeFiles/xobot.dir/file1.c.o
 cd /home/gr/x/xobot/dir1 && /usr/bin/gcc   -I/home/gr/x/xobot/include
   -o CMakeFiles/xobot.dir/file1.c.o   -c
/home/gr/x/xobot/dir1/file1.c
 Linking C executable xobot
...


А вот в файле зависимостей виден только глобальный <h1.h> и не виден "h1.h":

 % findx 'h1\.h'
...
 ./dir1/CMakeFiles/xobot.dir/depend.internal:6: include/h1.h
 ./dir1/CMakeFiles/xobot.dir/depend.make:5:dir1/CMakeFiles/xobot.dir/file1.c.o:
include/h1.h
...

Если имена не совпадают, то всё гладко:

 % findx 'h1\.h'
...
./dir1/CMakeFiles/xobot.dir/depend.internal:6: /home/gr/x/xobot/dir1/h2.h
./dir1/CMakeFiles/xobot.dir/depend.internal:7: include/h1.h
./dir1/CMakeFiles/xobot.dir/depend.make:5:dir1/CMakeFiles/xobot.dir/file1.c.o:
dir1/h2.h
./dir1/CMakeFiles/xobot.dir/depend.make:6:dir1/CMakeFiles/xobot.dir/file1.c.o:
include/h1.h
...

Остальные детали:

 % tree .
.
├── CMakeLists.txt
├── dir1
│   ├── CMakeLists.txt
│   ├── file1.c
│   └── h1.h
└── include
    └── h1.h

2 directories, 5 files

 % cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(oz C)
include_directories("include/")
add_subdirectory("dir1/")

 % cat dir1/CMakeLists.txt
add_executable(oz file1.c)

 % cat dir1/h1.h
#ifndef H1
#define H1

#include <stdio.h>

#define H "LOCAL1"

#endif /* H1 */

 % cat include/h1.h
#ifndef G1
#define G1

#define G "GLOBAL"

#endif /* G1 */


--
Гриша Тертычный


Reply to: