Does that result in building the code 3 times? 
And why would you need to repeat the install directives? 

I've attached a CMakeLists.txt file for an example project that works for me 
without repeating install directives. 

Clint 

----- Original Message -----

> Here's a follow-up.

> I was unable to get Jean-Christophes modification of Ansis' solution working.
> (I definitely did not want to repeat the install directives in this rather
> large project.) The " -DCMAKE_BUILD_TYPE" lines don't really accomplish
> anything when building with Visual Studio. I was making progress but
> ultimately gave up. Here is where I stopped.

> #####
> include(ExternalProject)

> ExternalProject_Add(MyProjectDebug
> PREFIX Debug
> SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
> CMAKE_ARGS -G ${CMAKE_GENERATOR} -D CMAKE_BUILD_TYPE=Debug -D
> CPACK_BUILD_CONFIG=Debug
> BUILD_COMMAND "${CMAKE_COMMAND}" --build
> ${CMAKE_BINARY_DIR}/Debug/src/MyProjectDebug-build --config Debug
> )

> ExternalProject_Add(MyProjectRelease
> PREFIX Release
> SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
> CMAKE_ARGS -G ${CMAKE_GENERATOR} -D CMAKE_BUILD_TYPE=Release -D
> CPACK_BUILD_CONFIG=Release
> BUILD_COMMAND "${CMAKE_COMMAND}" --build
> ${CMAKE_BINARY_DIR}/Release/src/MyProjectRelease-build --config Release
> )

> set(CPACK_INSTALL_CMAKE_PROJECTS
> "${CMAKE_BINARY_DIR}/Debug/src/MyProjectDebug-build;MyProject;ALL;/"
> "${CMAKE_BINARY_DIR}/Release/src/MyProjectRelease-build;MyProject;ALL;/"
> )

> include(CPack)
> #####

> At this point, the debug build would build in the debug tree and the release
> build in the release tree. All is well to that point. However, when I would
> attempt to use CPack with no -C option it would attempt to package Debug
> from the Release tree. When I would attempt to use CPack with a -C option,
> it would fail on one or the other (whichever one I did not specify).

> I tried a slight fork of the above using the NMake generator instead of the
> Visual Studio 10 generator but still ran into some issues local to our CMake
> files. I may try to resolve that next, but if anybody has any hints of where
> go from here that would be appreciated.

> Frankly it seems to me that we should be able to package multiple configs
> without any of this extra work.

> On Fri, Feb 8, 2013 at 2:50 AM, Yngve Inntjore Levinsen <
> yngve.levin...@gmail.com > wrote:

> > On 7/2/13 7:54 PM, Patrick Johnmeyer wrote:
> 

> > > On Thu, Feb 7, 2013 at 12:41 PM, Yngve Inntjore Levinsen <
> > > yngve.levin...@gmail.com > wrote:
> > 
> 

> > > > I think you are fighting the tool in any case, because you are asking
> > > > to
> > > > build multiple configurations in one build folder (?). Normally you
> > > > would
> > > > create one build folder per configuration.. Which I guess is what you
> > > > are
> > > > doing today.
> > > 
> > 
> 

> > > No, the Visual Studio generator is not a " single-configuration
> > > generator"
> > > .
> > > all configurations are bundled into the single generated solution file.
> > > This
> > > is the standard behavior of CMake under "basic" usage.
> > 
> 

> > > Your solution using ExternalProject looks promising, though, I will try
> > > this
> > > out. Thanks!
> > 
> 

> > Aha, I have mostly used the Makefile generator, and never VS, so I didn't
> > know that. I agree, the externalproject trick proposed by Ansis sounds
> > better. Good luck!
> 

> > Cheers,
> 
> > Yngve
> 

> --

> Powered by www.kitware.com

> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html

> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ

> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
cmake_minimum_required(VERSION 2.8)
project(myproject)

option(OPTION_XYZ "my option" OFF)

set(CMAKE_DEBUG_POSTFIX _d)
add_library(foo SHARED foo.cpp foo.hpp)

install(TARGETS foo DESTINATION lib)



option(CPACK_MULTICONFIG_PACKAGE "Enable creating a multi-config package with both debug and release (doubles compile time)" OFF)

if(CPACK_MULTICONFIG_PACKAGE)
  # If using makefiles, pick the other of Release/Debug as the build type.
  # If using visual studio with the configuration including both debug and release,
  # pick debug for the other configuration, as this one's cpack files will default to release.
  # The cpack user should not use the -C flag

  if(CMAKE_CONFIGURATION_TYPES)
    if(CMAKE_CONFIGURATION_TYPES MATCHES "([Rr][Ee][Ll][Ee][Aa][Ss][Ee])")
      set(other_config_type "Debug")
    else()
      set(other_config_type "Release")
    endif()
    set(other_config_flag "CMAKE_CONFIGURATION_TYPES:STRING=${other_config_type}")
  else()
    if(NOT CMAKE_BUILD_TYPE)
      message(SEND_ERROR "You must set CMAKE_BUILD_TYPE to Debug or Release")
    endif(NOT CMAKE_BUILD_TYPE)
    if(CMAKE_BUILD_TYPE MATCHES "([Rr][Ee][Ll][Ee][Aa][Ss][Ee])")
      set(other_config_type "Debug")
    else()
      set(other_config_type "Release")
    endif()
    set(other_config_flag "CMAKE_BUILD_TYPE:STRING=${other_config_type}")
  endif()

  include(ExternalProject)
  ExternalProject_Add(OtherConfig
    PREFIX OtherConfig
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
    CMAKE_GENERATOR ${CMAKE_GENERATOR}
    CMAKE_ARGS --no-warn-unused-cli
               -D OPTION_XYZ:BOOL=${OPTION_XYZ}
               -D CPACK_MULTICONFIG_PACKAGE:BOOL=OFF
               -D CMAKE_BUILD_TYPE=Debug -D CPACK_BUILD_CONFIG=Debug
               -D CMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
               -D CMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
               -D CMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS_ORIG}
               -D CMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
               -D CMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS_ORIG}
               -D ${other_config_flag} 
     BINARY_DIR OtherConfig
     INSTALL_COMMAND ""
    )
endif()


# tell cpack to package up both debug and release
if(CPACK_MULTICONFIG_PACKAGE)
  set(CPACK_INSTALL_CMAKE_PROJECTS 
    # self project
      "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/"
    # other config project
      "${CMAKE_BINARY_DIR}/OtherConfig;${CMAKE_PROJECT_NAME};ALL;/"
      )
endif()

include(CPack)

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to