Hello,

I think I've found a bug in the ninja generator. I wonder if it's fixed
already in a more recent cmake version.

I'm using cmake 3.3.1. My project uses ExternalProject_Add() to pull some
pre-built binaries from an internal repository in some configurations. In
other configurations however that same dependency may be picked from the
system, and yet in other configurations it is built from sources. So I want
to unify the usage by only requiring the user code to do
target_link_libraries().

I'm trying to utilize imported targets to achieve that. But I get errors
immediately after I run the build before any download can happen.

Here's a very simple CMakeLists.txt which allows to reproduce this on
Linux. The foo_file target imitates downloading. You'll need to provide
some trivial main.c, like "main() { return 0; }". If generated with the
Makefile generator the build starts and then fails with an expected error:
foo.so is indeed not a proper shared object. But if I generate for Ninja
the build fails immediately with the error: "ninja: error: 'foo.so', needed
by 'bar', missing and no known rule to make it"

------8<----CMakeLists.txt----------------------
cmake_minimum_required(VERSION 3.2)
add_custom_target(foo_file COMMAND ${CMAKE_COMMAND} -E touch foo.so)
add_library(foo SHARED IMPORTED)
add_dependencies(foo foo_file)
set_target_properties(foo PROPERTIES IMPORTED_LOCATION foo.so)
add_executable(bar main.c)
target_link_libraries(bar foo)
------8<----------------------------------------------

Should I file a bug report, or just switch to a newer CMake version?

Thanks,
SnakE
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to