gpt4 book ai didi

cmake不会在更改时重建externalProject

转载 作者:行者123 更新时间:2023-12-03 16:55:04 26 4
gpt4 key购买 nike

我有以下CMakeLists.txt:

cmake_minimum_required( VERSION 3.0)
project(addProject)
include (ExternalProject)

set(ExternalProjectCMakeArgs
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/external/genLib
)

ExternalProject_Add(genLib
SOURCE_DIR ${PROJECT_SOURCE_DIR}/external/genLib
BINARY_DIR ${PROJECT_BINARY_DIR}/external/genLib
INSTALL_COMMAND ""
INSTALL_DIR ${PROJECT_BINARY_DIR}/external
CMAKE_ARGS ${ExternalProjectCMakeArgs}
)
add_custom_command( OUTPUT "generated.cpp"
COMMAND ${PROJECT_BINARY_DIR}/external/genLib/genLib "generated.cpp"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

add_executable(add main.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated.cpp)
add_dependencies (add genLib)

第一次构建总是正确的:
mkdir build; cd build; cmake -GNinja ../; ninja

提供以下输出:
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler using: Ninja
-- Check for working CXX compiler using: Ninja -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Devel/scratc/testingExternalProject2/build
41% 5/12@2.7 0: Performing configure step for 'genLib'
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler using: Ninja
-- Check for working CXX compiler using: Ninja -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Devel/scratc/testingExternalProject2/build/external/genLib
50% 6/12@3.0 0: Performing build step for 'genLib'
50% 1/2@? 1: Building CXX object CMakeFiles/genLib.dir/genLib.cpp.o
100% 2/2@40.2 1: Linking CXX executable genLib
100% 12/12@5.6 0: Linking CXX executable add

现在,如果我在外部项目中修改源文件:
触摸../external/genLib/genLib.cpp

并重新编译
忍者
没有什么变化:
忍者:无事可做。

我已经使用make而不是Ninja用完全相同的行为对其进行了测试。
我还测试了在我的custom_command中添加DEPENDS子句,该子句适用于单个文件,但不适用于整个项目(并且似乎很难将外部项目的所有源文件作为DEPENDS子句添加...)

有谁有使用外部项目的更多经验,并且可以解释cmake决定重建还是不依赖的行为?

最佳答案

如果至少可以使用cmake 3.1版,请尝试将BUILD_ALWAYS 1添加到ExternalProject_Add命令:

ExternalProject_Add(genLib
SOURCE_DIR ${PROJECT_SOURCE_DIR}/external/genLib
BINARY_DIR ${PROJECT_BINARY_DIR}/external/genLib
BUILD_ALWAYS 1
INSTALL_COMMAND ""
INSTALL_DIR ${PROJECT_BINARY_DIR}/external
CMAKE_ARGS ${ExternalProjectCMakeArgs}
)

根据 ExternalProject_Add命令的文档

Enabling this option forces the build step to always be run. This can be the easiest way to robustly ensure that the external project’s own build dependencies are evaluated rather than relying on the default success timestamp-based method. This option is not normally needed unless developers are expected to modify something the external project’s build depends on in a way that is not detectable via the step target dependencies (e.g. SOURCE_DIR is used without a download method and developers might modify the sources in SOURCE_DIR).

关于cmake不会在更改时重建externalProject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46708124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com