为什么OBJECT_DEPENDS使用忍者生成器导致循环错误?

时间:2019-05-01 21:44:33

标签: c++ cmake ninja

我需要在CMake项目中进行破解。使用此技巧,必须先编译源文件之一,然后再编译其他文件。它与Makefile生成器一起使用。但是使用忍者生成器,我得到错误ninja: error: dependency cycle:。我试图找到任何信息来解决此问题,但没有成功。

简化的CMakeLists.txt

cmake_minimum_required(VERSION 3.0)

set(CMAKE_VERBOSE_MAKEFILE ON)

project(pchtest CXX)
set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_executable(${PROJECT_NAME} "main.cpp" "pch.cpp" "pch.h" "pch_dummy.cpp")

set_source_files_properties(pch.cpp PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch_dummy.cpp.o)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h.gch
    COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch.cpp.o ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h.gch
    COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch_dummy.cpp.o ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch.cpp.o
    COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h.gch

    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch.cpp.o
    COMMENT "Copy PCH"
)

set_source_files_properties(main.cpp PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h.gch)

错误:

ninja: error: dependency cycle: CMakeFiles/pch.h.gch -> CMakeFiles/pchtest.dir/pch.cpp.o -> CMakeFiles/pchtest.dir/pch_dummy.cpp.o -> cmake_object_order_depends_target_pchtest -> CMakeFiles/pch.h.gch

那该如何解决呢?

0 个答案:

没有答案