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

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

如果这听起来微不足道,我深表歉意。我刚开始使用 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 将我的编译器安装为 "compiler" 而不是 "Simple-C"。我希望正在安装的可执行文件的名称是 "Simple-C"。如何在我的 CMakeLists.txt 文件中执行此操作?

您可以使用 CMake installRENAME 选项。参见 https://cmake.org/cmake/help/v3.13/command/install.html

简而言之

install(TARGETS compiler DESTINATION bin RENAME Simple-C)

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

set_target_properties(compiler PROPERTIES OUTPUT_NAME Simple-C)

这必须在 add_subdirectory(compiler)

之后调用

附带说明一下,您提到的命令没有调用 cpack。为了调用 cpack,您需要 运行 cpack command.