MantisBT - CMake
View Issue Details
0015696CMakeCPackpublic2015-08-13 15:102016-01-04 11:52
Clinton Stimpson 
Clinton Stimpson 
normalminorhave not tried
closedfixed 
CMake 3.3 
CMake 3.4CMake 3.4 
0015696: cpack preinstall of subdirectory no longer works
For one cpack config file, I want to package up only a certain subdirectory.
For that, I set CPACK_INSTALL_CMAKE_PROJECTS


SET(CPACK_INSTALL_CMAKE_PROJECTS ${CMAKE_CURRENT_BINARY_DIR} MyProject "ALL" "/" )
INCLUDE(CPack)


When I run cpack, I get the following error:
CPack Error: Problem running install command: /usr/local/bin/cmake --build . --target "preinstall"
Please check /home/cjstimp/cmake/test-cpack-subdir/build/_CPack_Packages/Linux/ZIP/PreinstallOutput.log for errors
Use the attached example project.

From the build directory, run

cpack -G ZIP .
Git bisect reveals this commit introduced the error.

93a3ec8b7705c6edfa08a59a789d193fcb4cf4c1 is the first bad commit
commit 93a3ec8b7705c6edfa08a59a789d193fcb4cf4c1
Author: Brad King <brad.king@kitware.com>
Date: Tue Mar 31 10:26:29 2015 -0400

    CPack: Fix make tool selection during preinstall (0015483)
No tags attached.
gz test-cpack-subdir.tar.gz (489) 2015-08-13 15:10
https://public.kitware.com/Bug/file/5508/test-cpack-subdir.tar.gz
Issue History
2015-08-13 15:10Clinton StimpsonNew Issue
2015-08-13 15:10Clinton StimpsonFile Added: test-cpack-subdir.tar.gz
2015-08-13 15:15Brad KingProduct Version => CMake 3.3
2015-08-13 15:15Brad KingSummarycpack preinstall of subdirectory regression in 3.3 => cpack preinstall of subdirectory no longer works
2015-08-13 15:15Brad KingDescription Updatedbug_revision_view_page.php?rev_id=1867#r1867
2015-08-13 15:21Brad KingNote Added: 0039278
2015-08-13 15:21Brad KingAssigned To => Clinton Stimpson
2015-08-13 15:21Brad KingStatusnew => assigned
2015-08-13 15:33Clinton StimpsonNote Added: 0039279
2015-08-13 15:45Brad KingNote Added: 0039280
2015-08-17 10:22Brad KingNote Added: 0039290
2015-08-17 11:02Clinton StimpsonNote Added: 0039291
2015-08-18 10:12Brad KingStatusassigned => resolved
2015-08-18 10:12Brad KingResolutionopen => fixed
2015-08-18 10:12Brad KingFixed in Version => CMake 3.4
2015-08-18 10:12Brad KingTarget Version => CMake 3.4
2016-01-04 11:52Robert MaynardNote Added: 0040116
2016-01-04 11:52Robert MaynardStatusresolved => closed

Notes
(0039278)
Brad King   
2015-08-13 15:21   
IIUC this is specific to the Makefile generators because other generators do not support subdirectory builds.

We have to use "cmake --build ." to address 0015483, so fixing this will require teaching "cmake --build ." how to run "make" in a subdirectory when run the way CPack runs it in this case. It will have to detect that the given directory is a subdirectory by searching up for a CMakeCache.txt file.
(0039279)
Clinton Stimpson   
2015-08-13 15:33   
By the way, I had also been doing this with the Visual Studio generator, so it is not just the Makefile generator.

For the example to work under Visual Studio, a project() in the subdirectory would need to be added, and CPACK_INSTALL_CMAKE_PROJECTS would include that sub project name.

Would your suggested fix work in this case?

I also don't mind it running preinstall in the root directory instead of a subdirectory, if that means we can support all generators. Can't we make all generators work at each project level (where a project() call is used)?

Or does "PROJECTS" in CPACK_INSTALL_CMAKE_PROJECTS refer to something else?
(0039280)
Brad King   
2015-08-13 15:45   
Re 0015696:0039279: In both cases we need to find the CMakeCache.txt file to know what generator is in use. To avoid searching from arbitrary locations we should at least verify that the current directory has a CMakeFiles/ subdirectory before searching up. Once we have the CMakeCache.txt file we can load it to get the generator and construct the build command (as is done already). However, we can then run the build command in the originally specified directory.
(0039290)
Brad King   
2015-08-17 10:22   
I see commit:

 cmake: Add support for "--build ." in subdirectory
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ba1065ab [^]

Thanks. Does that resolve this issue? Is the proper command line now constructed?
(0039291)
Clinton Stimpson   
2015-08-17 11:02   
Yes, with that commit, this bug is now resolved.
I've tested under both Visual Studio and Makefiles.
(0040116)
Robert Maynard   
2016-01-04 11:52   
Closing resolved issues that have not been updated in more than 4 months.