How can I generate Visual Studio projects for a specific configuration?

Using CMake ExternalProject_Add

, I automate the build of my dependencies. However, I am creating configurations that do not match at the end, although I miss CMAKE_BUILD_TYPE

and BUILD_SHARED_LIBS

as described in the tutorial .

# SFML
include(ExternalProject)
set(SFML_PREFIX ${CMAKE_SOURCE_DIR}/SFML)

# Download, configure, build and install.
ExternalProject_Add(SFML
    # DEPENDS
    PREFIX         ${SFML_PREFIX}
    TMP_DIR        ${SFML_PREFIX}/temp
    STAMP_DIR      ${SFML_PREFIX}/stamp
    #--Download step--------------
    GIT_REPOSITORY https://github.com/LaurentGomila/SFML.git
    GIT_TAG        e2c378e9d1
    #--Update/Patch step----------
    UPDATE_COMMAND ""
    #--Configure step-------------
    SOURCE_DIR     ${SFML_PREFIX}/source
    CMAKE_ARGS     -DCMAKE_INSTALL_PREFIX:PATH=${SFML_PREFIX}/install
                   -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
                   -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
    #--Build step-----------------
    BINARY_DIR     ${SFML_PREFIX}/build
    #--Install step---------------
    INSTALL_DIR    ${SFML_PREFIX}/install
)

# Set root so that find module knows where to look.
set(SFML_ROOT ${SFML_PREFIX}/install)

      

How can I generate a Visual Studio project that builds release versions instead of returning to debug mode with no command line arguments? Is there a way to generate a project that builds both release and debug versions with one msbuild Project.sln

?

+2


source to share


1 answer


For generators with multiple configurations (such as Visual Studio), the actual build configuration (debug or release) is specified when the project is created. Setting the time CMAKE_BUILD_TYPE

during setup has no effect.

When using the Visual Studio generator, the command ExternalProject_Add

sets up the build process for the external project so that the project uses the build configuration currently selected in the IDE. In CMake terms, this means that the following code is executed:

cmake --build <BINARY_DIR> --config ${CMAKE_CFG_INTDIR}

      

For Visual Studio 10, ${CMAKE_CFG_INTDIR}

is replaced by $(Configuration)

at build time.



To always build a Release build, you must replace the default build step ExternalProject_Add

with a custom one:

ExternalProject_Add(SFML
    ...
    #--Build step-----------------
    BINARY_DIR ${SFML_PREFIX}/build
    BUILD_COMMAND
        ${CMAKE_COMMAND} --build <BINARY_DIR> --config Release
    ...
    )

      

To create Release and Debug versions, add another call to cakeake:

ExternalProject_Add(SFML
    ...
    #--Build step-----------------
    BINARY_DIR ${SFML_PREFIX}/build
    BUILD_COMMAND
        ${CMAKE_COMMAND} --build <BINARY_DIR> --config Release
        COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config Debug
    ...
    )

      

+3


source







All Articles