作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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
有什么解决办法吗?
最佳答案
看起来 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
恕我直言,这是文档问题
关于CMake 自定义构建步骤 PRE_LINK/PRE_BUILD 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25029895/
PRE_LINK 和 PRE_BUILD 似乎在 Linux 上的 CMake 中不起作用(生成 MakeFiles )。文档说仅不支持 PRE_BUILD。但是,PRE_LINK 根本不起作用。 我
在下面的 CMakeLists.txt 文件中,虽然我设置了一个带有 PRE_BUILD 选项的 add_custom_command 命令,但自定义命令并不总是在生成主要可执行文件之前执行: cma
我是一名优秀的程序员,十分优秀!