CMAKE-添加库在上一回的foreach中不起作用

时间:2018-07-12 10:28:16

标签: cmake logic

我有一个 CMakelist.txt

cmake_minimum_required(VERSION 3.12)
project(test)

set(TEST_HOME ${CMAKE_CURRENT_SOURCE_DIR})

message("test SDK home directory: " ${TEST_HOME})

set(a true)
list(APPEND plugins a)
set(b true)
list(APPEND plugins b)
set(c true)
list(APPEND plugins c)
add_executable(test main.c)

foreach(plugin IN LISTS plugins)
  if(${${plugin}})
    file(GLOB ${plugin}-SRC "${TEST_HOME}/plugins/${plugin}/src/*.c")
    message(${${plugin}-SRC})
    add_library(slt_${plugin} SHARED ${${plugin}-SRC})
    message(${plugin})
    target_link_libraries(test slt_${plugin}.so)
  endif()
endforeach()

TLDR:我准备创建库并将其链接到我的可执行文件。

但是我的上一个库未创建, CMakelist.txt 生成的 Makefile 的输出是:

Scanning dependencies of target slt_c
[ 12%] Building C object CMakeFiles/slt_c.dir/plugins/c/src/c.c.o
[ 25%] Linking C shared library libslt_c.so
[ 25%] Built target slt_c
Scanning dependencies of target slt_b
[ 37%] Building C object CMakeFiles/slt_b.dir/plugins/b/src/b.c.o
[ 50%] Linking C shared library libslt_b.so
[ 50%] Built target slt_b
[ 62%] Linking C executable minko
/usr/bin/x86_64-linux-gnu-ld: cannot find -lslt_a
/usr/bin/x86_64-linux-gnu-ld: cannot find -lslt_b
/usr/bin/x86_64-linux-gnu-ld: cannot find -lslt_c

当我将 a 设置为 false 时。是谁不建设。 我真的不知道是什么原因造成的,我只是通过一些测试开始了CMAKE。谢谢。

0 个答案:

没有答案