Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-18280

Build configuration 'current executable' does not work for CMake projects

    XMLWordPrintable

Details

    Description

      Looks like after 79f5a275 this functionality is broken.

      Steps to reproduce

      First, open a simple cmake project:

      cmake_minimum_required(VERSION 3.4)
      
      project(TestCurrentExecutable)
      
      if(NOT EXISTS "${CMAKE_BINARY_DIR}/a.cpp")
        file(WRITE "${CMAKE_BINARY_DIR}/a.cpp" "int main() {return 0;}")
      endif()
      add_executable(a "${CMAKE_BINARY_DIR}/a.cpp")
      

      Then in Project -> Build & Run -> (Some kit) -> Build -> Build Steps -> Targets choose Current executable and try to build. It will fail:

      21:10:15: Running steps for project TestCurrentExecutable...
      21:10:15: Persisting CMake state...
      21:10:16: Starting: cmake --build . --target /tmp/QtCreator-YoILoZ/qtc-cmake-XXSNwaq9/a
      ninja: error: unknown target '/tmp/QtCreator-YoILoZ/qtc-cmake-XXSNwaq9/a'
      21:10:16: The process "/home/dpantele/apps/cmake/bin/cmake" exited with code 1.
      Error while building/deploying project TestCurrentExecutable (kit: Desktop)
      When executing step "CMake Build"
      21:10:16: Elapsed time: 00:01.
      

      It is easy to see that instead of executing cmake --build . --target a there is an attempt to build target absolute path to executable

      Moreover, if one closes project and then reopens it, then it fails even before running cmake:

      :-1: error: You asked to build the current Run Configuration's build target only, but it is not associated with a build target. Update the Make Step in your build settings.
      

      CMakeRunConfiguration initialization defect

      When one tries to build 'current executable' target, CMakeRunConfiguration::m_buildSystemTarget is used as a target name. It is initialized from ct.executable.toString() (see CMakeRunConfigurationFactory::doCreate), which is an absolute path to the executable. Even only a filename of that can't be used - Makefiles generated by CMake contains only targets by names, and target name can be different from the executable name.

      CMakeRunConfiguration reopen defect

      CMakeRunConfigurationFactory::doRestore does sets m_buildSystemTarget to an empty string. While m_executable is updated later by setExecutable, m_buildSystemTarget is const and won't be changed, unless the whole CMakeRunConfiguration is recreated, and looks like this is not happening.

      Proposed changes

      It is my first look at QtCreator source, but I believe that it is safe to use id to compute m_buildSystemTarget:

      CMakeRunConfiguration::CMakeRunConfiguration(Target *parent, Core::Id id, const QString &target, ...) :
          RunConfiguration(parent, id),
          m_buildSystemTarget(CMakeRunConfigurationFactory::buildTargetFromId(id))
      

      Looks like it fixes all issues mentioned.

      Attachments

        Activity

          People

            hunger Tobias Hunger
            dpantele Dmitry Panteleev
            Votes:
            8 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: