cmake中的代码如下:
#设置安装目录的前缀
set(CMAKE_INSTALL_PREFIX $ENV{PUBLISH_DIR})
#这边的输出满足要求
message(STATUS "install dir:${CMAKE_INSTALL_PREFIX}")
#指定安装
install(TARGETS ${TARGET_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
运行的结果为:
1>-- Install configuration: "Release"
1>CMake Error at osslib/cmake_install.cmake:39 (file):
1> file cannot create directory: C:/Program Files/xxxx. Maybe need
1> administrative privileges.
1>Call Stack (most recent call first):
1> cmake_install.cmake:37 (include)
问题原因:
界面变量优先赋值导致本地set变量值不生效,
CMAKE_INSTALL_PREFIX 需要修改界面中的值,然后就可以得到正确的安装,setlocal无效是因为文件权限问题导致。