Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cmake添加自定义目标赢得';不允许if语句?_Cmake - Fatal编程技术网

cmake添加自定义目标赢得';不允许if语句?

cmake添加自定义目标赢得';不允许if语句?,cmake,Cmake,是否可以在add\u custom\u target中的一个命令中使用if语句?我想出了 add_custom_target(target if(linux) message("Linux!") endif() ) 但它在以下方面失败了: /bin/sh:1:语法错误:单词意外(应为“then”) 当我在if(linux)的末尾添加然后时,它会失败,原因是: /bin/sh:1:

是否可以在
add\u custom\u target
中的一个命令中使用if语句?我想出了

add_custom_target(target                 
             if(linux)
               message("Linux!")
             endif()
)
但它在以下方面失败了:

/bin/sh:1:语法错误:单词意外(应为“then”)

当我在if(linux)的末尾添加
然后
时,它会失败,原因是:

/bin/sh:1:语法错误:单词unexpected(expected”)”


为什么这不起作用?无法在添加\自定义\目标中进行测试吗?我的目的是根据操作系统在add_custom_目标中执行不同的操作。我还考虑过定义一个在add_custom_目标中调用的函数,但这也不起作用。该应用程序不允许我编写一个简单的
make
,这也是有问题的。

您应该在
ADD\u CUSTOM\u TARGET
之外使用if语句:

if(linux)
    add_custom_target(target message("Linux!"))
elseif(win32)
    add_custom_target(target message("Windows!"))
endif()

您应该在
ADD\u CUSTOM\u TARGET
之外使用if语句:

if(linux)
    add_custom_target(target message("Linux!"))
elseif(win32)
    add_custom_target(target message("Windows!"))
endif()

我通过将代码移动到cmake脚本中并通过cmake的脚本处理模式在add_custom_target中调用此脚本来解决问题:
cmake-p
我通过将代码移动到cmake脚本中并通过cmake的脚本处理模式在add_custom_target中调用此脚本来解决问题:
cmake-p
我试图避免这种情况,因为windows和linux有很多相同的代码。代码重复很糟糕!我试图避免这种情况,因为windows和linux有很多相同的代码。代码重复很糟糕!