[CMake] Alternative for INCLUDE_EXTERMAL_MSPROJECT for Visual Studio 2012 generator

David Cole dlrdave at aol.com
Sat Apr 26 07:21:52 EDT 2014


>    A simple example:
>
>     ------------ Sln1/CMakeLists.txt ----------------------
>     cmake_minimum_required(VERSION 2.8)
>       project(project1)
>       ADD_LIBRARY (project1 STATIC main.cpp)
>
>     ------------ Sln2/CMakeLists.txt ----------------------
>     cmake_minimum_required(VERSION 2.8)
>       project(project1)
>       ADD_LIBRARY (project1 STATIC main.cpp)
>
>       include(ExternalProject)
>         ExternalProject_Add(project1 SOURCE_DIR ../Sln1)
>


I get the following error when building your simple example. I'm
uncertain why you *don't* get the same error, because I knew I was
going to get something like this error when I just read your code. You
can't have both a library *and* a custom target with the same name...
In this case, you're using "project1" for both the library and the
external project name.

C:\dev\dcole\tmp\b2>cmake ..\Sln2
-- Building for: Visual Studio 11
-- The C compiler identification is MSVC 17.0.61030.0
-- The CXX compiler identification is MSVC 17.0.61030.0
-- Check for working C compiler using: Visual Studio 11
-- Check for working C compiler using: Visual Studio 11 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 11
-- Check for working CXX compiler using: Visual Studio 11 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at C:/Program Files (x86)/CMake
2.8/share/cmake-2.8/Modules/ExternalProject.cmake:1760
(add_custom_target):
   add_custom_target cannot create target "project1" because another
target
   with the same name already exists.  The existing target is a static
library
   created in source directory "C:/dev/dcole/tmp/Sln2".  See
documentation for
  policy CMP0002 for more details.
Call Stack (most recent call first):
  CMakeLists.txt:7 (ExternalProject_Add)


If I change 2 lines in Sln2/CMakeLists.txt, like this:

    project(project2)
    ADD_LIBRARY (project2 STATIC main.cpp)

Then I get a "project2.sln" file that builds project1 and project2 just
fine, but there is a problem with the INSTALL step of project1. To
avoid the problem with the install step, I added an empty
INSTALL_COMMAND to the ExternalProject_Add call, like this:

    ExternalProject_Add(project1 SOURCE_DIR ../Sln1 INSTALL_COMMAND "")


After those changes, it all works just as I think you're intending it
to work. (I used cmake 2.8.12.2 here... make sure you're using that, or
the latest release candidate of the upcoming CMake 3.0...)


Hope this helps,
David C.





More information about the CMake mailing list