CMake的每一个我include_directory添加新目录时重新编译一切() [英] Cmake recompiles everything each time I add a new directory in include_directory()

查看:2453
本文介绍了CMake的每一个我include_directory添加新目录时重新编译一切()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这个问题是非常相似的<一个href=\"http://stackoverflow.com/questions/28521613/cmake-recompiles-everything-each-time-i-add-a-new-source-subfolder\">this一个我问,但没有相关的GLOB微妙之处。所以分隔两个问题,会更清晰,我认为)

我每次添加或include_directory在我的CMakeLists.txt删除文件夹()(即使是空),然后键入

  cmake的。
使

触发重新编译整个项目。我为什么和能做些什么呢?

我实际的CMakeLists.txt(注意没有GLOB):

  cmake_minimum_required(版本2.8)
cmake_policy(VERSION 2.8.12.2)#项目
get_filename_component(项目名MyProject的NAME)
项目($ {}项目名)#编译器和选项
集(CMAKE_CXX_COMPILER的/ usr / bin中/铛++)
集(CLANG_COMPILE_FLAGS-std = C ++ 1Y -stdlib = ++的libc)构建#类型
集(CMAKE_BUILD_TYPE发行)
#构建工具
集(CMAKE_GENERATOR的Unix的Makefile)集(EXECUTABLE_OUTPUT_PATH ../bin/${CMAKE_BUILD_TYPE})
集(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} $ {CLANG_COMPILE_FLAGS})
集(CMAKE_EXE_LINKER_FLAGS$ {CMAKE_EXE_LINKER_FLAGS} $ {CLANG_LINK_FLAGS})include_directories(
    #在这里添加任何[这里包含.h文件所有文件夹]触发整个项目重新编译
)add_executable(
    $ {}项目名
    [这里所有的.cpp和.h文件]


解决方案

命令 include_directories 添加编译标志(如 -I /路径/要/包括/ DIR GCC )。所以,如果你改变 include_directories =>编译器标志更改=>目标必须重建。

示例

要避免整个项目重新编译经常需要不能修改 include_directories 常。举个例子,你可以组织code是这样的:

 的CMakeLists.txt
资源/
         - A / foo.hpp
         - A / Foo.cpp中
         - B / boo.hpp
         - B / boo.cpp

的CMakeLists.txt内容:

  include_directories(./来源)
add_executable(myexe A / foo.hpp A / Foo.cpp中B / boo.hpp B / boo.cpp)

C ++的文件内容:

 的#includeA / foo.hpp
#包括B / boo.hpp

(This question is quite similar to this one I asked but is not related to the GLOB subtleties. So separating the two problems would be clearer I think)

Each time I add or remove a folder in include_directory() (even empty) in my CMakeLists.txt, then typing

cmake .
make

triggers the whole project to be recompiled. Why and what can I do about it?

My actual CMakeLists.txt (note there is no GLOB):

cmake_minimum_required(VERSION 2.8)
cmake_policy(VERSION 2.8.12.2)

# Project
get_filename_component(ProjectName MyProject NAME)
project(${ProjectName})

# Compiler and options
set(CMAKE_CXX_COMPILER /usr/bin/clang++)
set(CLANG_COMPILE_FLAGS "-std=c++1y -stdlib=libc++ ")

# Type of build
set(CMAKE_BUILD_TYPE "Release")
# Build tool 
set(CMAKE_GENERATOR "Unix Makefiles")

set(EXECUTABLE_OUTPUT_PATH ../bin/${CMAKE_BUILD_TYPE})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLANG_COMPILE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CLANG_LINK_FLAGS}")

include_directories(
    [all folders containing .h files here] # adding anything here triggers the whole project to recompile
)

add_executable(
    ${ProjectName}
    [all .cpp and .h files here]
)

解决方案

Command include_directories add compiler flags (e.g. -I/path/to/include/dir for gcc). So if you change include_directories => compiler flags changes => target need to be rebuild.

Example

To avoid regular recompilation of whole project you need to not modify include_directories often. As an example you can organize code like this:

CMakeLists.txt
Source/
        - A/foo.hpp
        - A/foo.cpp
        - B/boo.hpp
        - B/boo.cpp

Content of CMakeLists.txt:

include_directories(./Source)
add_executable(myexe A/foo.hpp A/foo.cpp B/boo.hpp B/boo.cpp)

Content of C++ files:

#include "A/foo.hpp"
#include "B/boo.hpp"

这篇关于CMake的每一个我include_directory添加新目录时重新编译一切()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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