我需要根据操作系统更改以下代码中的cmake PREFIX。
尝试过这样:
INCLUDE(ExternalProject)
EXTERNALPROJECT_ADD(
libconfig
URL ${CMAKE_CURRENT_SOURCE_DIR}/libconfig-1.4.8.tar.gz
IF(APPLE)
#Mac detected
PREFIX libconfig/libconfig-1.4.8
ENDIF(APPLE)
IF(UNIX)
PREFIX libconfig
ENDIF(UNIX)
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --disable-examples
# We patch in order to avoid building the tests.
# Otherwise compilation will fail due to relative paths used in libconfig.
PATCH_COMMAND patch < ${CMAKE_CURRENT_SOURCE_DIR}/libconfig.patch
BUILD_COMMAND make
INSTALL_COMMAND make install
)
答案 0 :(得分:6)
我发现了问题:
首先,测试IF(UNIX)对于Mac OS X操作系统也是如此。
第二个是以某种方式不能改变PREFIX。因此,解决方法是使用变量。
此代码现在有效:
IF(UNIX)
SET(LIBCONFIG_PREFIX libconfig)
ENDIF(UNIX)
IF(APPLE)
SET(LIBCONFIG_PREFIX libconfig/libconfig-1.4.8)
ENDIF(APPLE)
INCLUDE(ExternalProject)
EXTERNALPROJECT_ADD(
libconfig
URL ${CMAKE_CURRENT_SOURCE_DIR}/libconfig-1.4.8.tar.gz
PREFIX ${LIBCONFIG_PREFIX}
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --disable-examples
# We patch in order to avoid building the tests.
# Otherwise compilation will fail due to relative paths used in libconfig.
PATCH_COMMAND patch < ${CMAKE_CURRENT_SOURCE_DIR}/libconfig.patch
BUILD_COMMAND make
INSTALL_COMMAND make install
)