dimanche 19 juillet 2020

Adjust CMake project name based on MSVC variable

I want to create my project name per my compiler (different names for MSVC or GNU).

I have the following code:

if(MSVC)
    project(Block3Windows ...)
else()
    project(Block3Linux ..)
endif()

These are the first commands in my CMakeLists.txt file. However, it always enters the else block.

It seems like the MSVC variable gets populated only after the call to project, to test it I've wrote the following:

if(MSVC)
    message(MSVC)
endif()
message(MSVC)
project(Block3Windows ...)
message("After Project")
message(MSVC)

I get the following printed:

First run:

After Project
MSVC

Second and later runs (with cache):

MSVC
After Project
MSVC

Why the MSVC from withing the first condition is never being printed ?

This behavior is not mentioned in the MSVC documentation

Am I missing something? How do I create a project name per logic on my compiler environment?

I'm using CMake 3.17.2

Aucun commentaire:

Enregistrer un commentaire