PRE_LINK和PRE_BUILD似乎不适用于Linux上的CMake(生成MakeFiles)。文档说只支持PRE_BUILD。但是,PRE_LINK根本不会受到影响。
我不确定他们是否理解错误或者我错过了什么。
(目前,作为解决方法,我添加了一个假目标和POST_BUILD步骤。然后创建依赖工作。但是,它有自己的问题。对于我的设置,它会在并行make(-j)完成时产生问题。
示例代码:
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
对此有何解决方案?
答案 0 :(得分:4)
看起来PRE_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
恕我直言,