[CMake] Generate and install a file

Kyle Edwards kyle.edwards at kitware.com
Thu Mar 28 16:12:02 EDT 2019


On Thu, 2019-03-28 at 16:07 -0400, Norton Allen wrote:
> Kyle,
> What you say makes sense, and I can even understand why
> add_custom_target might do that, but I cannot get this to actually
> work. Here is a minimal CMakeLists.txt. mysourcefile is just and
> empty file.
> I have these files in test/cmake, and I:
> cd test
> mkdir build-cmake
> cd build-cmake
> cmake ../cmake
> make
> and there is no sign of mygeneratedfile. I then try
> make install
> and I get:
> $ make install
> Install the project...
> -- Install configuration: ""
> CMake Error at cmake_install.cmake:31 (file):
>   file INSTALL cannot find "/home/nort/test/build-
> cmake/mygeneratedfile".
> 
> 
> make: *** [Makefile:84: install] Error 1
> Where is my mistake?
One more thing: if you want the custom target to be built by "make" or
"make all", you have to give it the ALL argument:
add_custom_target(mygeneratedtarget ALL
  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/mygeneratedfile
)
Otherwise you can build the target with "make mygeneratedtarget".
Kyle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190328/c825a9ba/attachment.html>


More information about the CMake mailing list