Search code examples
visual-studio-2012cmakeexternal-project

missing project after using ExternalProject_Add


I'm using VS2012+cmake2.8.12. My problem is that CMake failed to generate the correct path to my external project. For example:

Project("{...}") = "external", "external.vcxproj", "..."  

whereas 'external.vcxproj' should be something like ..\path\to\external.vcxproj

Here is how I use ExternalProject_Add command:

ExternalProject_Add(external SOURCE_DIR ${CMAKE_SOURCE_DIR}/../../int/external
                    CMAKE_ARGS ..
                    BINARY_DIR ${CMAKE_SOURCE_DIR}/../../int/external/build)

Any help is highly appreciated!


Solution

  • Building Visual Studio projects with ExternalProject_Add works slightly different. The whole ExternalProject module is platform-independent and unaware of the peculiarities of Visual Studio's build system. Thus just adding a VS project will not work, since ExternalProject does not know how to build it. Instead you have to specify the full command line for building the project. Something like:

    ExternalProject_Add(external_test
        SOURCE_DIR ${PROJECT_SOURCE_DIR}
        CONFIGURE_COMMAND ""
        BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} ${PROJECT_SOURCE_DIR}/path/to/external.sln /build Release /project optional_project_within_solution
        INSTALL_COMMAND "")
    

    As you can see, it's quite a mess. If you just want to include an existing VS project with your CMake generated solution, consider using include_external_msproject instead.