用什么替换set_target_properties找不到要向其添加属性的目标:myTarget?

时间:2018-10-02 15:49:06

标签: cmake

所以问题很简单。 我有以下CMakeList.txt(我仅复制第一行,因为我相信其余内容并不重要):

cmake_minimum_required(VERSION 2.6)

###############              Project name          #####################
project(myProject)

###############            Minimal flags           #####################   
if(NOT DEFINED CMAKE_MACOSX_RPATH)
  set(CMAKE_MACOSX_RPATH 0)
endif()

#######   Check the compiler and set the compile and link flags  #######
set_target_properties(myTarget PROPERTIES
    CXX_STANDARD 11
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
)
set(CMAKE_BUILD_TYPE Debug)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/../config/cmake")

但出现以下错误:

Make Error at CMakeLists.txt:29 (set_target_properties):
  set_target_properties Can not find target to add properties to: myTarget

我发现了这一点:CMake error "Can not find target to add properties to" 但是我认为并非如此。因此:https://cliutils.gitlab.io/modern-cmake/chapters/features/small.html

我所见过的所有示例均与该代码相似,表示我必须添加一个库作为目标,但不知道我应该使用哪个库。

您知道出了什么问题或用什么替换了myTarget吗?

1 个答案:

答案 0 :(得分:0)

如@vre所说。只需将set_target_properties更改为:

set(CMAKE_CXX_STANDARD 11) 
set(CMAKE_CXX_STANDARD_REQUIRED ON) 
set(CMAKE_CXX_EXTENSIONS OFF)

足够好并且可以正确编译。