CMake自定义生成步骤预链接/预生成不起作用
PRE_链接和PRE_构建在linux上的CMake中似乎不起作用(生成MakeFiles)。文档中说,只支持预构建。但是,PRE_LINK根本不起作用 我不确定是否理解错了,或者我是否遗漏了什么 (目前,作为解决方案,我在其上添加了一个假目标和后期构建步骤。然后创建依赖项就起作用了。但是,它也有自己的问题。对于我的设置,当并行生成(-j)完成时,它会产生问题 示例代码:CMake自定义生成步骤预链接/预生成不起作用,cmake,Cmake,PRE_链接和PRE_构建在linux上的CMake中似乎不起作用(生成MakeFiles)。文档中说,只支持预构建。但是,PRE_LINK根本不起作用 我不确定是否理解错了,或者我是否遗漏了什么 (目前,作为解决方案,我在其上添加了一个假目标和后期构建步骤。然后创建依赖项就起作用了。但是,它也有自己的问题。对于我的设置,当并行生成(-j)完成时,它会产生问题 示例代码: cmake_minimum_required(VERSION 2.8.5) project(custom_command_t
cmake_minimum_required(VERSION 2.8.5)
project(custom_command_test)
add_custom_target(my_actual_target
COMMAND echo " I am the actual taget "
COMMENT "Running actual target"
)
add_custom_command(
TARGET my_actual_target
PRE_LINK
COMMAND echo "I am prelinked to actual target"
COMMENT " Running PRELINK action "
)
add_custom_command(
TARGET my_actual_target
PRE_BUILD
COMMAND echo " I am prebuilt to actual target"
COMMENT " Running PRE_BUILD action"
)
add_custom_command(
TARGET my_actual_target
POST_BUILD
COMMAND echo " I postbuild to actual target"
COMMENT " Running POST BUILD action "
)
输出:
> cmake .
-- The C compiler identification is GNU 4.4.2
-- The CXX compiler identification is GNU 4.4.2
-- Check for working C compiler: XXXX/gcc/4.4.2/bin/gcc
-- Check for working C compiler: XXXX/gcc/4.4.2/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: XXXX/gcc/4.4.2/bin/g++
-- Check for working CXX compiler: XXXX/gcc/4.4.2/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: XXXX
> make my_actual_target
Scanning dependencies of target my_actual_target
[100%] Running actual target
I am the actual taget
Running PRE_BUILD action
I am prebuilt to actual target
Running POST BUILD action
I postbuild to actual target
[100%] Built target my_actual_target
> cmake --version
cmake version 2.8.10.2
此问题的任何解决方案都类似于
PRE\u LINK
仅适用于“真实”目标,如库或可执行文件:
add_library(my_actual_target foo.cpp)
add_custom_command(
TARGET my_actual_target
PRE_LINK
COMMAND echo "I am prelinked to actual target"
COMMENT " Running PRE_LINK action "
)
add_custom_command(
TARGET my_actual_target
PRE_BUILD
COMMAND echo " I am prebuilt to actual target"
COMMENT " Running PRE_BUILD action"
)
add_custom_command(
TARGET my_actual_target
POST_BUILD
COMMAND echo " I postbuild to actual target"
COMMENT " Running POST_BUILD action "
)
结果:
Running PRE_BUILD action
...
Running PRE_LINK action
...
Running POST_BUILD action
我知道这是文档问题但是在实际目标之前运行PRE_LINK/PRE_BUILD命令怎么样?在我上面的示例中,PRE_BUILD是在实际目标之后生成/运行的。看起来你是对的!!这被认为是文档问题。下面是错误报告: