MantisBT - CMake
View Issue Details
0015748CMakeCMakepublic2015-09-16 18:202016-02-01 09:10
James Johnston 
Stephen Kelly 
normalmajoralways
closedfixed 
Visual Studio 2008Windows 7
CMake 3.4 
CMake 3.4CMake 3.4 
0015748: Regression: get_target_property dies if a source file does not exist
Previously, in CMake 3.3, one could call get_target_property to retrieve the deprecated LOCATION target property even if not all source files exist yet. Now, in CMake master branch (commit febeabbf0b221a19bd4bf16ba7620af22d8dba17) this does not work under some conditions. The bug is a little tricky to isolate into a test case - e.g. not all calls to get_target_property will die. (e.g. if you call get_target_property from the same dir that creates the target, it seems to work). I am also not sure if the LOCATION property is the only target property affected by this.

Even though LOCATION is deprecated, this matters because very recent OpenCV versions still use it (e.g. in OpenCV/cmake/OpenCVGenPkgconfig.cmake).
1. Create file CMakeLists.txt with this contents:

cmake_minimum_required(VERSION 2.6.3)
project(SourceTest)
add_subdirectory(subdir)
# Critical: this needs to happen in root CMakeLists.txt and not inside
# the subdir.
get_target_property(mypath Hello LOCATION_${CMAKE_BUILD_TYPE})
# Now we create the file later, so you can see, ultimately no error should
# happen e.g. during generate phase:
configure_file(subdir/Hello.c.in ${CMAKE_CURRENT_BINARY_DIR}/subdir/Hello.c)

2. Create subdir/CMakeLists.txt with this contents:

add_executable(Hello ${CMAKE_CURRENT_BINARY_DIR}/Hello.c)

3. The contents of subdir/Hello.c.in can be a simple Hello World program. (actually the contents do not matter to repro this bug since you don't get to compile phase...).

4. Configure the project:

cmake -GNinja ../SourceTest

5. I get this error:

CMake Error at subdir/CMakeLists.txt:1 (add_executable):
  Cannot find source file:

    C:/Users/JamesJ/Documents/Repositories/OI3D-2/SourceTest-build/subdir/Hello.
c

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx


-- Configuring incomplete, errors occurred!
No tags attached.
Issue History
2015-09-16 18:20James JohnstonNew Issue
2015-09-16 18:22James JohnstonSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=1903#r1903
2015-09-17 09:27Brad KingTarget Version => CMake 3.4
2015-09-17 09:28Brad KingAssigned To => Stephen Kelly
2015-09-17 09:28Brad KingStatusnew => assigned
2015-09-17 09:29Brad KingNote Added: 0039435
2015-09-18 14:11Stephen KellyNote Added: 0039441
2015-09-18 14:33Stephen KellyNote Added: 0039445
2015-09-18 14:51Stephen KellyNote Edited: 0039445bug_revision_view_page.php?bugnote_id=39445#r1905
2015-09-21 09:22Brad KingNote Added: 0039461
2015-09-21 09:22Brad KingStatusassigned => resolved
2015-09-21 09:22Brad KingResolutionopen => fixed
2015-09-21 09:22Brad KingFixed in Version => CMake 3.4
2016-02-01 09:10Robert MaynardNote Added: 0040414
2016-02-01 09:10Robert MaynardStatusresolved => closed

Notes
(0039435)
Brad King   
2015-09-17 09:29   
This bisects to somewhere around:

 cmTarget: Create cmGeneratorTargets before reading deprecated LOCATION.
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ba266858 [^]

That commit fails but a few preceding commits segfault on the example.
(0039441)
Stephen Kelly   
2015-09-18 14:11   
Thanks for the reproducing example!

Fixed with

 CMP0026: Use compatibility codepath until configure is finished (0015748)
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d02c5b6e [^]
(0039445)
Stephen Kelly   
2015-09-18 14:33   
(edited on: 2015-09-18 14:51)
That commit caused some test failures.

I reverted it until the cause of the test failures is known.

(0039461)
Brad King   
2015-09-21 09:22   
Here is the revised fix:

 CMP0026: Use compatibility codepath until configure is finished
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2514e426 [^]

Thanks, Steve.
(0040414)
Robert Maynard   
2016-02-01 09:10   
Closing resolved issues that have not been updated in more than 4 months.