如何更改使用 CPack 安装的可执行文件的名称?

How do I change the name of the executable that I'm installing using CPack?

本文关键字:可执行文件 安装 何更改 CPack      更新时间:2023-10-16

如果这听起来像是微不足道的事情,我确实提前道歉。我是使用CMake和CPack的新手。

我目前正在尝试构建自己的编译器作为副项目,我想测试 CPack 将如何安装我的项目。

这是我的CMakeLists.txt文件,我位于项目文件夹的根目录中:

cmake_minimum_required(VERSION 3.15)
project(Simple-C-Compiler VERSION 0.01)
set(CMAKE_CXX_STANDARD 20)
set(COMPILER_VERSION ${PROJECT_VERSION})
add_library(include INTERFACE)
target_include_directories(include INTERFACE include/)
add_subdirectory(lib)
add_subdirectory(phases)
add_subdirectory(compiler)
add_subdirectory(tests)
target_link_libraries(compiler lexer)
target_link_libraries(tester lexer)
add_compile_options(-Wall)
install(TARGETS compiler DESTINATION bin)
set(CPACK_PACKAGE_EXECUTABLES "compiler" "Simple-C")
include(CPack)

当我尝试安装编译器时,请执行以下操作:

mkdir build
cd build
cmake ../
make install

我得到以下输出:

[ 22%] Built target lib
[ 55%] Built target lexer
[ 77%] Built target compiler
[100%] Built target tester
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/compiler

CPack 将我的编译器安装为"编译器"而不是"Simple-C"。我希望正在安装的可执行文件的名称为"Simple-C"。如何在我的 CMakeLists.txt 文件中执行此操作?

您可以使用以下命令更改目标的名称:

set_target_properties(compiler PROPERTIES OUTPUT_NAME Simple-C)

这必须在add_subdirectory(compiler)之后调用

作为旁注,您提到的命令没有调用 cpack。为了调用 cpack,您需要运行 cpack 命令。

您可以使用CMakeinstallRENAME选项。请参阅 https://cmake.org/cmake/help/v3.13/command/install.html

总之

install(TARGETS compiler DESTINATION bin RENAME Simple-C)