[CMake] [cmake-developers] CMake IR

Dan Kegel dank at kegel.com
Fri Jul 31 12:38:27 EDT 2015


On Fri, Jul 31, 2015 at 11:33 AM, Ruslan Baratov
<ruslan_baratov at yahoo.com> wrote:
>>> I never use the GUI, and consider the cache an anti-feature there solely
>>> to support GUI users.  It complicates my life, and I'd love to see it go.
>>
>> In what way do you think it is causing you trouble?
>
> Here is an example:
>
>     # CMakeLists.txt
>     cmake_minimum_required(VERSION 3.0)
>     project(Foo)
>
>     if(A)
>       set(B "Hello A" CACHE STRING "Do we use A?")
>     else()
>       set(B "There is no A" CACHE STRING "Do we use A?")
>     endif()
>
> User thinks: okay, if I set A=ON I will have B equal to "Hello A".
>
> What user really have:
>
>     > rm -rf _builds
>     > cmake -H. -B_builds
>     > cmake -H. -B_builds -DA=ON
>     > grep '\<B\>' _builds/CMakeCache.txt
>     B:STRING=There is no A
>
> I'm not saying cache is a bad idea, I'm just saying that when users hit such
> kind of situations that's one of the reason why they said CMake is not a
> good script language. Just like CMake before CMP0054: user see `if("a"
> STREQUAL "b")` and think "okay, 'a' is not equal to 'b' so this condition is
> always false"... nope!

Here's another example from real life.  Maybe I'm just being an idiot,
but this is what I had to do to set a default:

IF(DEFINED CMAKE_BUILD_TYPE AND (NOT ${CMAKE_BUILD_TYPE} STREQUAL "None"))
   SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the
type of build, options are: Debug Release RelWithDebInfo")
ELSE()
   SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type
of build, options are: Debug Release RelWithDebInfo" FORCE)
ENDIF()

Can someone give me the proper one-line way to set a default for
CMAKE_BUILD_TYPE, or is this an authentic problem?
- Dan


More information about the CMake mailing list