5

EDIT: I have found a probable cause but I do not understand why: the last line in the below script Project(Externals) when removed fixes my issue. So the question now why??

cmake_minimum_required(VERSION 2.8)

include(ExternalProject)

MACRO(EXTERNAL_DEF aNewTargetName aPathToSource)
  ExternalProject_Add(
    ${aNewTargetName}
    PREFIX ${CMAKE_INSTALL_PREFIX}
    SOURCE_DIR ${aPathToSource}

    TMP_DIR      "${CMAKE_INSTALL_PREFIX}/tmp/${CMAKE_BUILD_TYPE}"
    DOWNLOAD_DIR "${CMAKE_INSTALL_PREFIX}/src/${CMAKE_BUILD_TYPE}"
    BINARY_DIR   "${CMAKE_INSTALL_PREFIX}/src/${CMAKE_BUILD_TYPE}/${aNewTargetName}-build"
    STAMP_DIR    "${CMAKE_INSTALL_PREFIX}/src/${CMAKE_BUILD_TYPE}/${aNewTargetName}-stamp"
    CMAKE_ARGS
      -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
      -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
      --debug-output
    BUILD_COMMAND "${CMAKE_COMMAND}" --build
      "${CMAKE_INSTALL_PREFIX}/src/${CMAKE_BUILD_TYPE}/${aNewTargetName}-build" --config "${CMAKE_BUILD_TYPE}"
    #INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
    )
ENDMACRO()

get_filename_component(zlibAbsPath "./zlib" ABSOLUTE)
EXTERNAL_DEF(zlib_external ${zlibAbsPath})
Project(Externals)

I invoke cmake on the above CMakeLists.txt file with CMAKE_INSTALL_PREFIX set to let's say "d:\externals" and CMAKE_BUILD_TYPE set to "Release"

Expectation: I would expect only the Release configuration to get built. And after it gets built I would expect it to get installed in D:\externals\bin\zlib.dll.

Problem: In reality, ExternalProject_Add builds both a Debug and a Release, and installs the debug version of the dll in D:\externals\bin\zlibd.dll

Isn't my build script correct? What am I doing wrong?

EDIT: some more info. I just noticed. In the generated D:\externals\src\Release\zlib_external-build\zlib.sln, the INSTALL target is not selected to build at all. If I check it to build for the Release configuration then hit "Build" from visual studio, the INSTALL target builds and installs the files where I expect them. I have no idea what's going on...

RAM
  • 2,257
  • 2
  • 19
  • 41
Ed Rowlett-Barbu
  • 1,611
  • 10
  • 27

2 Answers2

4

CMAKE_BUILD_TYPE only work with single-configuration projects

you can change to:

  BUILD_COMMAND ""
  INSTALL_COMMAND
    ${CMAKE_COMMAND}
    --build .
    --target install
    --config Release
  BUILD_ALWAYS 1 
starball
  • 20,030
  • 7
  • 43
  • 238
fe263
  • 107
  • 8
-3

Use DCMAKE_CFG_INTDIR variable.

...
CMAKE_ARGS
    ...
    -DCMAKE_CFG_INTDIR=Release
rxed
  • 1
  • 1
    From the docs of [`CMAKE_CFG_INTDIR`](http://www.cmake.org/cmake/help/v2.8.12/cmake.html#variable:CMAKE_CFG_INTDIR): `This variable is read-only. Setting it is undefined behavior.`. – ComicSansMS Mar 10 '14 at 12:46