Cmake: Change PREFIX to EXTERNALPROJECT_ADD depending on the operating system

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

He tried this as follows:

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 ) 
+4
source share
1 answer

I found problems:

First, the test IF (UNIX) also applies to Mac OS X operating systems.

Secondly, something 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 ) 
+6
source

All Articles