MantisBT - CMake
View Issue Details
0013588CMake(No Category)public2012-10-15 04:332013-03-04 08:38
vkaramov 
 
normalminorhave not tried
closedwon't fix 
PCUbuntu Linux 6412.04
CMake 2.8.7 
 
0013588: target_link_libraries fails if one of the libraries is NOTFOUND
My target which is dynamic library, uses some static libs:

target_link_libraries(${lib_name}
debug ${do_scoring_debug}
optimized ${do_scoring}
)
When I tried to build Release configuration of my library, build fails because do_scoring_debug == NOTFOUND at that time.
It seems strange to me, because linker doesn't need *Debug* version of ${do_scoring} when building *Release* version of target.
No tags attached.
gz fail.tar.gz (691) 2012-10-15 09:46
https://public.kitware.com/Bug/file/4521/*
Issue History
2012-10-15 04:33vkaramovNew Issue
2012-10-15 08:25Brad KingNote Added: 0031234
2012-10-15 09:46vkaramovFile Added: fail.tar.gz
2012-10-16 04:11vkaramovNote Added: 0031240
2012-10-16 06:58Brad KingNote Added: 0031242
2012-10-16 09:23Brad KingNote Added: 0031246
2012-10-16 09:23Brad KingStatusnew => resolved
2012-10-16 09:23Brad KingResolutionopen => won't fix
2013-03-04 08:38Robert MaynardNote Added: 0032473
2013-03-04 08:38Robert MaynardStatusresolved => closed

Notes
(0031234)
Brad King   
2012-10-15 08:25   
I cannot reproduce this. Please attach a minimal but complete example source tarball.
(0031240)
vkaramov   
2012-10-16 04:11   
I could reproduce it on 2 computers with Ubuntu 12.04 AMD64.
(0031242)
Brad King   
2012-10-16 06:58   
Your description said "one of the libraries is NOTFOUND". It is actually "one of the libraries is FIND_RESULT-NOTFOUND":


$ cat ../CMakeLists.txt
cmake_minimum_required(VERSION 2.8.7)
project(Issue13588 C)
add_executable(fail main.c)
target_link_libraries(fail debug m-NOTFOUND optimized m)

$ cmake --version
cmake version 2.8.9

$ cmake .. -DCMAKE_BUILD_TYPE=Release
...
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:
m
    linked by target "fail" in directory ...

The check is here:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGlobalGenerator.cxx;hb=v2.8.9#l1125 [^]

and is so old that it pre-dates the optimized/debug keywords.

Furthermore, there is a regression in 2.8.10-rc1 in that it does not check for foo-NOTFOUND results correctly.
(0031246)
Brad King   
2012-10-16 09:23   
In multi-config generators like VS and Xcode the check is correct because all configurations are generated at once. If you want to ensure libs that are not found do not get used, do something like

 find_library(mylib_RELEASE ...)
 find_library(mylib_DEBUG ...)

 if(mylib_RELEASE AND mylib_DEBUG)
   set(mylib_LIBRARIES optimized ${mylib_RELEASE} debug ${mylib_DEBUG})
 elseif(mylib_RELEASE)
   set(mylib_LIBRARIES ${mylib_RELEASE})
 elseif(mylib_DEBUG)
   set(mylib_LIBRARIES ${mylib_DEBUG})
 else()
   message(SEND_ERROR "No mylib found!")
 endif()
 # ...
 target_link_libraries(${mytarget} ${mylib_LIBRARIES})

Some find modules do this already.

The regression noted in 0013588:0031242 will be addressed before 2.8.10 final.
(0032473)
Robert Maynard   
2013-03-04 08:38   
Closing resolved issues that have not been updated in more than 4 months.