MantisBT - CMake
View Issue Details
0015626CMakeCMakepublic2015-06-23 13:492016-02-01 09:10
Andrew Fuller 
Brad King 
highcrashalways
closedfixed 
LinuxUbuntu14.04
 
CMake 3.3CMake 3.3 
0015626: 3.3-rc2 segfault (regression)
Manipulating a target that was first created in a different directory branch causes a segfault.
1. Create the following CMake files:

$ tree
.
├── CMakeLists.txt
├── dirA
│   └── CMakeLists.txt
└── dirB
    └── CMakeLists.txt

$ cat CMakeLists.txt

add_subdirectory( dirA )
add_subdirectory( dirB )

$ cat dirA/CMakeLists.txt

add_library( foo INTERFACE )

$ cat dirB/CMakeLists.txt

target_link_libraries( foo INTERFACE ${CMAKE_DL_LIBS} )

2. Configure
$ mkdir build && cd build && cmake ..
[...]
[1] 6691 segmentation fault (core dumped) cmake ..
This works fine with CMake 3.2.1.
No tags attached.
Issue History
2015-06-23 13:49Andrew FullerNew Issue
2015-06-23 14:50Brad KingNote Added: 0038962
2015-06-23 14:50Brad KingAssigned To => Stephen Kelly
2015-06-23 14:50Brad KingStatusnew => assigned
2015-06-23 14:50Brad KingTarget Version => CMake 3.3
2015-06-25 11:00Brad KingNote Added: 0038984
2015-06-25 11:00Brad KingAssigned ToStephen Kelly => Brad King
2015-06-25 11:00Brad KingStatusassigned => resolved
2015-06-25 11:00Brad KingResolutionopen => fixed
2015-06-25 11:00Brad KingFixed in Version => CMake 3.3
2015-06-25 11:15Andrew FullerNote Added: 0038985
2015-06-25 11:54Brad KingNote Added: 0038986
2015-06-25 12:13Andrew FullerNote Added: 0038987
2016-02-01 09:10Robert MaynardNote Added: 0040400
2016-02-01 09:10Robert MaynardStatusresolved => closed

Notes
(0038962)
Brad King   
2015-06-23 14:50   
Thanks. This bisects to:

 cmTarget: Store only cmListFileContext for CMP0023 handling.
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=52a8d19c [^]
(0038984)
Brad King   
2015-06-25 11:00   
Fixed and test case added:

 cmTarget: Fix diagnostic of target_link_libraries in wrong directory
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=30c2e1dd [^]

I've queued this for merge to 'release' for 3.3.0-rc3.
(0038985)
Andrew Fuller   
2015-06-25 11:15   
If I'm reading the commit correctly, the fix is to report an error (better than crashing). Is there a CMP I can set to have the old behaviour? Or is there something I can test to determine whether it's safe to modify the target? In my current code I'm checking if( TARGET foo ), but that's only testing whether the target has been declared which no longer aligns with can-I-poke-it.
(0038986)
Brad King   
2015-06-25 11:54   
Re 0015626:0038985: There is no behavior change from CMake 3.2. Using target_link_libraries to add INTERFACE settings from another directory is still allowed. Using target_link_libraries to actually change how a target itself links was never allowed and still is not. Both cases excercise the code path that caused this crash. I just chose the latter for the test case.
(0038987)
Andrew Fuller   
2015-06-25 12:13   
Wonderful. I just tried it and it's working well.
(0040400)
Robert Maynard   
2016-02-01 09:10   
Closing resolved issues that have not been updated in more than 4 months.