Run a CMake superbuild once and only once

Cameron Lowell Palmer

In a CMake superbuild it is desirable to run the dependency build and project build the first time and then never again (unless desired). The problem I'm having with options and set is that I haven't found a way to set an initial value and then override it.

Top-Level CMakeLists.txt

if( NOT DEFINED USE_SUPERBUILD )
    set( USE_SUPERBUILD on CACHE BOOL "Set the superbuild to run once" )
else()
    set( USE_SUPERBUILD ${USE_SUPERBUILD} CACHE BOOL "Set the superbuild to run once" FORCE )
    message( "Forcing USE_SUPERBUILD AFTER: ${USE_SUPERBUILD}" )
endif()

superbuild.cmake

ExternalProject_Add( my_proj
        DEPENDS ${MYPROJ_DEPENDENCIES}
        SOURCE_DIR ${PROJECT_SOURCE_DIR}
        CMAKE_ARGS -DUSE_SUPERBUILD:BOOL=off ${EXTRA_CMAKE_ARGS}
        INSTALL_COMMAND ""
        BINARY_DIR ${INSTALL_DIR} ) 

Running it

Forcing USE_SUPERBUILD AFTER: off

CMakeCache.txt

//Set the superbuild to run once
USE_SUPERBUILD:BOOL=on

When the superbuild gets to the end, it calls this script with USE_SUPERBUILD=off and it should store this value. For some reason even though it is getting to the else() block and setting off but the CMakeCache.txt still contains on. So the problem here is clearly the ExternalProject_add not calling the build such that it uses the root of the CMAKE_BINARY_DIR when you started. Is there a way to make ExternalProject_add work the same as calling cmake -DUSE_SUPERBUILD=off ../project_source_folder?

Cameron Lowell Palmer

Switch from ExternalProject_add

The working directory is wrong with ExternalProject_add can be replaced with add_custom_target.

add_custom_target( my_proj ALL
        DEPENDS ${MYPROJ_DEPENDENCIES}
        COMMAND cmake -DUSE_SUPERBUILD:BOOL=off ${EXTRA_CMAKE_ARGS} --build ${CMAKE_BINARY_DIR}
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
        COMMENT "Starting build ${CMAKE_BINARY_DIR}" )

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related