使用CLion,如何将可执行文件安装到只能由root写入的目录中?

时间:2018-06-21 13:14:47

标签: bash unix cmake permissions clion

我正在macOS High Sierra上使用CLion构建C项目。我的CMakeLists.txt看起来像这样:

cmake_minimum_required(VERSION 3.10)
project(toy C)

set(CMAKE_C_STANDARD 11)

add_executable(toy main.c)
target_compile_options(toy PRIVATE -Wall -Wextra -pedantic -c)
target_link_libraries(toy kcgi z)

install(TARGETS toy
        DESTINATION /var/www/fcgi-bin
        PERMISSIONS OWNER_EXECUTE OWNER_READ
                    GROUP_EXECUTE GROUP_READ
                    WORLD_EXECUTE WORLD_READ)

但是,在我的系统上,/var/www/fcgi-bin仅可由root用户写入:

~|⇒ ls -la /var/www/fcgi-bin
total 0
drwxr-xr-x  2 root  wheel   64 Jun 21 21:11 .
drwxr-xr-x  7 root  wheel  224 Jun 15 22:45 ..

当我尝试安装目标时,出现错误,可能是由于权限问题导致的:

/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/sunqingyao/CLionProjects/toy/cmake-build-debug --target install -- -j 2
[100%] Built target toy
Install the project...
-- Install configuration: "Debug"
-- Installing: /var/www/fcgi-bin/toy
CMake Error at cmake_install.cmake:44 (file):
  file INSTALL cannot copy file
  "/Users/sunqingyao/CLionProjects/toy/cmake-build-debug/toy" to
  "/var/www/fcgi-bin/toy".


make: *** [install] Error 1

chmod(1)上使用/var/www/fcgi-bin是最明显的解决方案,但是我不想修改目标目录的权限。我想要的是等效于CMake的

install: kcgi-app
        sudo mkdir -p /var/www/fcgi-bin
        sudo install -m 0555 kcgi-app /var/www/fcgi-bin

这可能吗?

0 个答案:

没有答案