您可以从另一个文件中包含一个共同的cmake最低要求吗?

时间:2019-08-24 12:41:09

标签: cmake

我对使用Makefile背景进行cmake很陌生。

我喜欢使用include(cmake_utils/header.cmake)之类的东西来包含通用的cmake文件片段,以便可以将它们包含在我的项目中,但只能一次更改一次。其中cmake_utils是git仓库。

这很好,但是我写的每个CMakeLists.txt都必须有一个cmake_minimum_required

那很好,但是我可能想改变这一天-可以说,当我的一个通用文件使用更新版本的cmake的功能时。在那种情况下,我不想四处更改所有CMakeLists.txt-我只想在一处(理想情况下)进行更改。

这是我当前的CMakeFile.txt:

cmake_minimum_required(VERSION 3.10.2)

# Include common elements
include(cmake_utils/header.cmake)
include(cmake_utils/cpp_flags.cmake)

# Include path
include_directories(
    inc
    inc/log4cpp
)

# Include source files by wild card
file(GLOB SOURCES "src/log4cpp/*.cpp")

# Setup output and libs
include(cmake_utils/output_lib_shared.cmake)
include(cmake_utils/common_libs.cmake)

我真的想将行cmake_minimum_required(VERSION 3.10.2)移到我的cmake_utils/header.cmake文件中。

但是,当我这样做时,我在调用cmake结束时得到了以下错误:

CMake Error in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.10)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".

这仅仅是我必须忍受的cmake的限制,还是有办法将其存档?

还有可能我仍像gnu make作家那样思考,而我全都错了:o

1 个答案:

答案 0 :(得分:1)

根据文档cmake_minimum_requiredCall the cmake_minimum_required() command at the beginning of the top-level CMakeLists.txt file even before calling the project() command. It is important to establish version and policy settings before invoking other commands whose behavior they may affect.

没有办法解决这个问题。