Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generator expression evaluates WIN32 variable to true even not on Windows

Tags:

cmake

I work on Ubuntu, and here is a part of my CMake code (the questionable part is in the last sentence):

include(ExternalProject)
ExternalProject_Add(fftw3_external
  URL
    http://www.fftw.org/fftw-3.3.8.tar.gz
  URL_HASH
    MD5=8aac833c943d8e90d51b697b27d4384d
  DOWNLOAD_NO_PROGRESS
    1
  UPDATE_COMMAND
    ""
  LOG_CONFIGURE
    1
  LOG_BUILD
    1
  LOG_INSTALL
    1
  CMAKE_ARGS
    -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
    -DBUILD_TESTS=OFF
  CMAKE_CACHE_ARGS
    -DCMAKE_C_FLAGS:STRING=$<$<BOOL:WIN32>:-DWITH_OUR_MALLOC>
  )

After configuration I look inside the corresponding cache file, fftw3_external-cache.cmake, and it shows:

set(CMAKE_C_FLAGS "-DWITH_OUR_MALLOC" CACHE STRING "Initial cache" FORCE)

But this content corresponds to WIN32 being true. Why it is so?

like image 218
Afterbunny Avatar asked Oct 27 '25 01:10

Afterbunny


1 Answers

In the generator expression

$<BOOL:WIN32>

CMake evaluates "WIN32" as a string, not as a variable. Because this string doesn't correspond to any false pattern, it is evaluated as TRUE.

You need to dereference the variable for check its value:

$<BOOL:${WIN32}>
like image 74
Tsyvarev Avatar answered Oct 29 '25 11:10

Tsyvarev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!