CMake:如何在制作目标后写入文件?

时间:2013-06-03 11:01:01

标签: c++ cmake

CMake中以下make文件代码的等效内容是什么?

target: config_header $(OBJS)
    g++ -o $(APPNAME) $(OBJS) $(LIBDIR) $(LIBS)

config_header:
    echo "#ifndef _CONFIG_HEADER_H_" > Config.h
    echo "#define _CONFIG_HEADER_H_" >> Config.h
    echo "#define MAJOR_VERSION \"$(MAJOR)\"" >> Config.h
    echo "#define MINOR_VERSION \"$(MINOR)\"" >> Config.h
    echo "#define PATCH_VERSION \"$(PATCH)\"" >> Config.h
    echo "#define RELEASE_VERSION \"$(RELEASE)\"" >> Config.h
    echo "#endif" >> Config.h

1 个答案:

答案 0 :(得分:1)

这会将您的cmake配置文件复制到二进制目录并调整已定义的参数。

#############################################################################
# Cmake generated header files
#############################################################################
CONFIGURE_FILE(
    ${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/config.hpp
)

config.hpp.cmake文件包含:

#ifndef GUARD
#define GUARD

#cmakedefine _CONFIG_HEADER_H_

#endif //GUARD

在复制期间,cmake会生成以下文件:

#ifndef GUARD
#define GUARD

#define _CONFIG_HEADER_H_

#endif //GUARD