conan-io / cmake-conan

CMake wrapper for conan C and C++ package manager
MIT License
831 stars 252 forks source link

conan_cmake_run() does not produce real-time build output #129

Closed Talkless closed 5 years ago

Talkless commented 5 years ago
$ conan --version
Conan version 1.12.3
$ cmake --version
cmake version 3.7.2
 uname -a
Linux vostro 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) x86_64 GNU/Linux

I have this CMakeLists.txt to test conan usage:

cmake_minimum_required(VERSION 3.7 FATAL_ERROR)

project(cmaketest LANGUAGES CXX)

add_executable(cmaketest "")

target_sources(cmaketest PRIVATE src/main.cpp)

set_target_properties(cmaketest PROPERTIES 
                INSTALL_RPATH "$ORIGIN"
                BUILD_WITH_INSTALL_RPATH TRUE)

# Download automatically, you can also just copy the conan.cmake file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
   message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
   file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.13/conan.cmake"
                 "${CMAKE_BINARY_DIR}/conan.cmake")
endif()

include(${CMAKE_BINARY_DIR}/conan.cmake)

conan_cmake_run(CONANFILE conanfile.txt
                BUILD missing)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

set(CONAN_LIBS_POCO PocoFoundation)

conan_basic_setup(TARGETS SKIP_RPATH)

target_link_libraries(cmaketest CONAN_PKG::Poco)

conanfile.txt:

[requires]
Poco/1.9.0@pocoproject/stable

[options]
Poco:shared=True
Poco:cxx_14=True
Poco:enable_xml=False
Poco:enable_json=False
Poco:enable_mongodb=False
Poco:enable_pdf=False
Poco:enable_util=False
Poco:enable_net=True
Poco:enable_netssl=False
Poco:enable_netssl_win=False
Poco:enable_crypto=False
Poco:enable_data=False
Poco:enable_data_sqlite=False
Poco:enable_data_mysql=False
Poco:enable_data_odbc=False
Poco:enable_sevenzip=False
Poco:enable_zip=False
Poco:enable_apacheconnector=False
Poco:enable_cppparser=False

[generators]
cmake

[imports]
lib, libPocoFoundation* -> ./

src/main.cpp:

#include <iostream>
#include <Poco/Random.h>

int main() {
    Poco::Random r;
    std::cout << "Poco::Random: " << r.next() << '\n';
}

When I run cmake ../ -DCMAKE_BUILD_TYPE=Release, and conan needs to build dependent libraries, for most of the time I see this fixed output:

$ cmake ../ -DCMAKE_BUILD_TYPE=Release                                                                   
-- Conan: Automatic detection of conan settings from cmake                                                                                                             
-- Conan: Settings= -s;build_type=Release;-s;compiler=gcc;-s;compiler.version=6;-s;compiler.libcxx=libstdc++11                                                        
-- Conan executing: conan install /home/vincas/code/test/cmaketest/conanfile.txt -s build_type=Release -s compiler=gcc -s compiler.version=6 -s compiler.libcxx=libstdc
++11 -g=cmake --build=missing

And only much later, at the end, I get full output, with CMake build progress, etc. At first, I thought something crashe/frozed, but CPU fan starting to spin up changed my mind :) .

Is this design limitation to see real-time build procedure output via conan_cmake_run ?

Morwenn commented 5 years ago

Same issue: I'm sometimes recompiling huge libraries with potentially a few hours of compilation, so having the build output of Conan in real time would be a huge benefit to just know how much longer I'm supposed to wait.

This probably could be instrumented through a VERBOSE option to conan_cmake_run or some equivalent.

stilgarpl commented 5 years ago

That can be fixed very easily. Just replace at line 376: this:

    execute_process(COMMAND ${conan_command} ${conan_args}
                     RESULT_VARIABLE return_code
                     OUTPUT_VARIABLE conan_output
                     ERROR_VARIABLE conan_output                     
                     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

    message(STATUS "${conan_output}")

with this:

    execute_process(COMMAND ${conan_command} ${conan_args}
                     RESULT_VARIABLE return_code                 
                     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

Everything will be printed to stdout and stderr at real time, without wait. It doesn't break anything, because the output message is printed to stdout anyway after conan execution is finished.

memsharded commented 5 years ago

Thanks for the feedback. This has been implemented in https://github.com/conan-io/cmake-conan/commit/857403c74b284679526084c8f6eea50f2d38d7c9, will be released in 0.14.

puetzk commented 5 years ago

Just to note, this change re-introduces the problem fixed in #100, though (server mode will no longer receive the output at all). Though with CMake 3.14 introducing https://cmake.org/cmake/help/v3.14/manual/cmake-file-api.7.html and 3.15 deprectating the https://cmake.org/cmake/help/v3.14/manual/cmake-server.7.html maybe that's OK (after 857403c74b284679526084c8f6eea50f2d38d7c9 it works better for the new way, and not at all for the older, now-deprecated way).

Kind of sucks until IDEs catch up, but VS2019 has adopted the new file API, and hopefully Qt creator eventually will.