Using CMake + Ninja (custom build option)

CodeLite installation/troubleshooting forum
Dobrelius
CodeLite Curious
Posts: 3
Joined: Fri Aug 03, 2018 12:13 am
Genuine User: Yes
IDE Question: C++
Contact:

Using CMake + Ninja (custom build option)

Post by Dobrelius »

Hello,

I'm working on Windows 7, trying to use CodeLite 12.04 with CMake 3.12 to create Ninja build files, then use CodeLite to start the Ninja build job.

I'm able to get the whole process to work fine when I use the command line to invoke CMake and Ninja manually.

However, the only way I have found to run Ninja from within the IDE is to enable the custom build option. Unfortunately, when I do that, the CMakeLists.txt file that CodeLite exports is incomplete. It only contains just a couple of lines describing project name and default locations, but none of the actual project settings or filenames. As a result, Ninja just reports that there is no work to do.

To compile the project from within the IDE, I have to disable the custom build option, run/export CMake, then re-enable custom build to run Ninja.

Is there a way I can get this to work without having to toggle the custom build option all the time?
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CMake + Ninja (custom build option)

Post by eranif »

The proper solution to do this is:
- Define a custom compiler (copy an existing compiler), this can be done from: Settings->Build Settings
- In the new compiler (let say you named it: "G++ with Ninja"), in the "Tools" tab, change the "Make" tool to point to the ninja.exe binary you have installed
- Close the build dialog and click OK
- Open your project settings and make sure that:
- Makefile generator is set to "CMake"
- In the "Arguments" field, set this: "-G Ninja"
- In the "Compiler" field (still in the "General" page) select the compiler "G++ for Ninja"

Caveats:
In the released version (12.0.4) CodeLite will execute "ninja.exe -e" (notice the extra "-e")
This is because CodeLite assumes that the "Make" is actually pointing to a "make" tool...
To workaround this:

1) Create a simple batch file with this content:

ninja.bat:

Code: Select all

D:\bin\ninja.exe
2) Change the path ninja.exe to the location you have installed Ninja on your machine
3) Settgings->Build Settings->Compilers->G++ for Ninja->Tools->Make, change it from "ninja.exe" to "ninja.bat"

No hitting F7 will execute the "ninja.bat" script
This workaround is no longer needed in CodeLite built from git master

Eran
Make sure you have read the HOW TO POST thread
Dobrelius
CodeLite Curious
Posts: 3
Joined: Fri Aug 03, 2018 12:13 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CMake + Ninja (custom build option)

Post by Dobrelius »

Thanks a lot. I was able to solve the problem with the workaround you suggested.
Post Reply