[CMake] using "INSTALL(CODE ..." for multiple configurations.

Campbell Barton ideasman42 at gmail.com
Mon May 30 06:54:40 EDT 2011


On Mon, May 30, 2011 at 1:55 AM, Michael Hertling <mhertling at online.de> wrote:
> On 05/30/2011 02:58 AM, Campbell Barton wrote:
>> Checking if this is possible since its quite verbose to have the same
>> command 4 times, one for each configuration.
>>
>> For blender3d on windows we need to extract python into the install
>> dir since we bundle it.
>>
>> This command looks like this:
>> --- snip
>>
>> install(
>>       CODE
>>       "
>>       execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir
>> \"${TARGETDIR_VER}/python/lib\"
>>               \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python32.tar.gz\")
>>       "
>>       CONFIGURATIONS Release
>> )
>>
>> --- snip
>>
>> The annoyance is that the same command needs to be called 3 times,
>> Release/RelWithDebInfo/MinSizeRel
>> Is there some way to list multiple 'CONFIGURATIONS' ?
>
> CMake's documentation states about INSTALL()'s CONFIGURATIONS
> argument: "The CONFIGURATIONS argument specifies a *list* of
> build configurations for which the install rule applies
> (Debug, Release, etc.)."
>
>> Ideally in this case Id like to have any 'Debug' extract
>> python32_d.tar.gz and any other configuration extract python32.tar.gz,
>> but a ways to have multiple configurations do one command would at
>> least be less verbose.
>
> Are you sure that the CONFIGURATIONS clause is available for the
> INSTALL(CODE ...) command? It's not specified, and on *nix, the
> following CMakeLists.txt issues the message upon "make install"
> regardless of the CMAKE_BUILD_TYPE variable's value whereas the
> INSTALL(FILES ...) command is sensitive as expected:
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
> PROJECT(INSTCONF NONE)
> SET(CMAKE_VERBOSE_MAKEFILE ON)
> INSTALL(CODE "MESSAGE(\"Installing\")" CONFIGURATIONS Release)
> INSTALL(FILES ${CMAKE_SOURCE_DIR}/CMakeLists.txt
>        DESTINATION ${CMAKE_BINARY_DIR}/cmake
>        CONFIGURATIONS Release)
>
> Does it work differently on Windows?
>
> Regards,
>
> Michael

Looked into this further, First, multiple configurations can be passed
separated by either spaces or ;.

So this works as expected:
---
	install(
		FILES ${LIBDIR}/python/lib/python32.dll
		DESTINATION ${TARGETDIR}
		CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
	)
---

You're right, the install(CODE ... doesn't support configurations, in
fact our install target on windows was extracting python 4 times!

Instead I added a check in the CODE
---
	install(
		CODE
		"
		if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" STREQUAL \"Debug\")
			execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir
\"${TARGETDIR_VER}/python/lib\"
				\"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python32_d.tar.gz\")
		else()
			execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir
\"${TARGETDIR_VER}/python/lib\"
				\"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python32.tar.gz\")
		endif()
		"
	)
---

Since CONFIGURATIONS is listed as an option I assumed it would work
with all install uses of install.
It would be good if the cmake docs mentioned which commands support
CONFIGURATIONS (FILES/DIRECTORY only?), I re-read and couldn't find
anything relating to this.

- Campbell


More information about the CMake mailing list