Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExternalProject_Add doesn't install the Release configuration of the project

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...

like image 886
Ed Rowlett-Barbu Avatar asked Nov 13 '22 06:11

Ed Rowlett-Barbu


1 Answers

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 
like image 119
fe263 Avatar answered Jan 04 '23 01:01

fe263