tune2fs
tune2fs

Reputation: 7705

cmake: Change PREFIX in EXTERNALPROJECT_ADD depending on Operating System

I need to change the cmake PREFIX in the following code depending on the operating system.

It tried it this way:

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
)

Upvotes: 4

Views: 3129

Answers (1)

tune2fs
tune2fs

Reputation: 7705

I found the problems:

The first was that the test IF(UNIX) is also true for Mac OS X Operating Systems.

The second is that somehow PREFIX cannot be changed. Therefore a workaround is to use a variable.

This code now works:

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
)

Upvotes: 6

Related Questions