Bug 349877

Summary: CMake doesn't select proper generator after prune.
Product: [Applications] kdevelop Reporter: Gianni <nasus.maximos>
Component: Build tools: CMakeAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: minor CC: aleixpol
Priority: NOR    
Version First Reported In: git master   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Proposed patch.

Description Gianni 2015-07-03 22:17:37 UTC
I have some rules in CMake which cause the build dir to be non-empty after a prune.  Running a configure in the build dir, will then be missing the '-G Ninja'.

Reproducible: Always

Steps to Reproduce:
1. Prune
2. Configure


Actual Results:  
Unix Makefile (the default) is selected as the generator:

build> /.../cmake -DCMAKE_INSTALL_PREFIX=/usr/local /home/.../project


Expected Results:  
Have Ninja as the generator:

build> /.../cmake -DCMAKE_INSTALL_PREFIX=/usr/local -G Ninja /home/.../project

In projectbuilders/cmakebuilder/cmakejob.cpp

The command line for cmake is built with or without the '-G' option, if the build dir is detected to be empty (or inexistant):

//if we are creating a new build directory, we'll want to specify the generator
QDir builddir(CMake::currentBuildDir( m_project ).toLocalFile());
   if(!builddir.exists() || builddir.count()==2) {

However, in my case, the build dir is present and non-empty (some wierd reason why, not important for this issue), but make hasn't run yet.

I propose a better check, which is to see if the CMakeCache.txt file is present, which it should *always* be created if cmake hasn't run.  Even if it has, and this file is missing, cmake will run as if it is the first time.  Therefore, the presence of this file is a better check if the build dir is ready in cmake's eyes.
Comment 1 Gianni 2015-07-03 22:20:12 UTC
Sorry, steps to reproduce is missing a steop:

1. Prune
2. cd build; touch test
3. Configure
Comment 2 Gianni 2015-07-03 22:24:51 UTC
Created attachment 93474 [details]
Proposed patch.
Comment 3 Kevin Funk 2015-11-29 15:04:46 UTC
@Aleix: Patch looks sane to me. Can you double-check & commit?
Comment 4 Gianni 2017-02-03 13:24:35 UTC
So.  Almost 2 years.  Any chance of merging this?
Comment 5 Aleix Pol 2017-02-14 11:57:14 UTC
Git commit fdd6636711a9e5d58a7c18b2f520ee8ef7ec0285 by Aleix Pol, on behalf of Gianni from Bugzilla.
Committed on 14/02/2017 at 11:57.
Pushed by apol into branch '5.1'.

Specify generator whenever there's no CMakeCache.txt

M  +1    -1    projectbuilders/cmakebuilder/cmakejob.cpp

https://commits.kde.org/kdevelop/fdd6636711a9e5d58a7c18b2f520ee8ef7ec0285