2017-02-20 53 views
1

我正在等待來自外部源的庫的調試版本,他們已經提供了發佈版本。CMake抱怨在構建版本時找不到調試庫

我們使用Find ...模塊來定位庫。現在,這導致類似:

optimized;libfoo.a;debug;foo-NOTFOUND 

該文件的CMakeLists.txt:

... 
add_executable(main main.c) 
target_link_libraries(main ${foo}) 

與啓動構建:

cmake source/dir -DCMAKE_BUILD_TYPE=Release 

但仍的CMake抱怨調試庫失蹤。

CMake Error: The following variables are used in this project, but they are set to NOTFOUND. 
Please set them or make sure they are set and tested correctly in the CMake files: 
foo 
    linked by target "main" in directory source/dir 

這是預期的行爲?如果不更改我們的查找模塊或在每次使用之前強制設置foo變量,我可以避免這個問題嗎?

回答

0

我已經給它一個嘗試,你不能壓制這個錯誤。查看責任源代碼cmGlobalGenerator::CheckTargetProperties()此檢查僅跳過INTERFACE鏈接庫(您顯然不想要,因爲它不會鏈接任何內容到main)。

但是你可以聲明名稱的佔位符IMPORTED庫不會像錯誤:

add_library(foo-NOTFOUND STATIC IMPORTED) 

要重現你的問題,並測試修復我設置以下CMakeLists.txt

cmake_minimum_required(VERSION 3.3) 
project(FooNotFound) 
cmake_policy(SET CMP0057 NEW) 

set(foo "optimized;libfoo.a;debug;foo-NOTFOUND") 
file(WRITE main.c "int main(void) { return 0; }") 

if ("foo-NOTFOUND" IN_LIST foo) 
    add_library(foo-NOTFOUND STATIC IMPORTED) 
endif() 

add_executable(main main.c) 
target_link_libraries(main INTERFACE ${foo})