1
# If the user hasn't told use specifically what they want, build only
# a static library.

IF(NOT DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)
   SET(PODOFO_BUILD_STATIC TRUE)
   SET(PODOFO_BUILD_SHARED FALSE)
ENDIF(NOT DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)

IF(DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)
    SET(PODOFO_BUILD_SHARED NOT ${PODOFO_BUILD_SHARED})
ENDIF(DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)

IF(NOT DEFINED PODOFO_BUILD_SHARED AND DEFINED PODOFO_BUILD_STATIC)
    SET(PODOFO_BUILD_SHARED NOT ${PODOFO_BUILD_STATIC})
ENDIF(NOT DEFINED PODOFO_BUILD_SHARED AND DEFINED PODOFO_BUILD_STATIC)

“SET(PODOFO_BUILD_SHARED NOT ${PODOFO_BUILD_SHARED})”是什么意思?在这些片段之前,我看不到 PODOFO_BUILD_SHARED 变量的任何定义

4

1 回答 1

1
  • 前 4 行采用 2 个“布尔”变量 PODOFO_BUILD_STATIC 和 PODOFO_BUILD_SHARED,如果它们都未定义,则将它们设置为默认值
  • 如果仅定义了 PODOFO_BUILD_SHARED,则后 3 行反转 PODOFO_BUILD_SHARED 的值,无论其初始值是什么。奇怪的!
  • 如果只定义了 PODOFO_BUILD_STATIC,最后 3 行取 PODOFO_BUILD_STATIC 的反转值并将其分配给 PODOFO_BUILD_SHARED

但是,整体行为似乎有点奇怪。我的猜测是这个(后三行):

IF(DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)
    SET(PODOFO_BUILD_SHARED NOT ${PODOFO_BUILD_SHARED})
ENDIF(DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)

应该:

IF(DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)
    SET(PODOFO_BUILD_STATIC NOT ${PODOFO_BUILD_SHARED})
ENDIF(DEFINED PODOFO_BUILD_SHARED AND NOT DEFINED PODOFO_BUILD_STATIC)

通过这种方式,它更有意义:如果只定义了 2 个变量中的一个,它将另一个设置为相反的值。

“SET(PODOFO_BUILD_SHARED NOT ${PODOFO_BUILD_SHARED})”是什么意思?在这些片段之前,我看不到 PODOFO_BUILD_SHARED 变量的任何定义

变量可以在文件外部以多种方式预先定义(例如,从命令行,或通过设置缓存变量cmake-gui

于 2013-11-07T12:11:08.543 回答