2

I have the following extremely simple project:

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.6)
project(myapp)

add_executable(myapp myapp.cpp)
install(TARGETS myapp RUNTIME DESTINATION bin)

set(CPACK_PACKAGE_NAME "MyApp")
set(CPACK_PACKAGE_VERSION_MAJOR 1)
set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH 0)
set(CPACK_INSTALL_SCRIPT DoSomething.cmake)

include(CPack)

myapp.cpp:

#include <iostream>

int main()
{
    std::cout << "Hello, world!" << std::endl;
}

DoSomething.cmake

message(WARNING "This message should be displayed.")

The project builds fine, but I run into issues when I attempt to run CPack:

nathan@nathan-desktop:/tmp/myapp/build$ cpack
CPack: Create package using STGZ
CPack: Install projects
CPack: - Install scripts: DoSomething.cmake
CPack: - Install script: DoSomething.cmake
CPack Error: Error when generating package: MyApp

What does this mean? What was the error? CPack doesn't seem to have generated any logs or provide any further details. Commenting out the contents of DoSomething.cmake doesn't seem to make any difference.

According to the documentation:

CPACK_INSTALL_SCRIPT

Extra CMake script provided by the user.

If set this CMake script will be executed by CPack during its local [CPack-private] installation which is done right before packaging the files. The script is not called by e.g.: make install.

Why won't my package build and my warning message display?

4

1 回答 1

1

一个老问题,但答案是您需要使用绝对路径,如下所示:

set(CPACK_INSTALL_SCRIPT ${CMAKE_SOURCE_DIR}/DoSomething.cmake)
于 2016-11-14T18:16:26.720 回答