这是我的cmake的简化版本
cmake_minimum_required(VERSION 2.8.4)
project(math)
add_library(math math.cpp)
function(install_package)
install(TARGETS math
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
add_custom_command(TARGET math
POST_BUILD
COMMAND cmake ARGS -P cmake_install.cmake)
endfunction()
install_package()
但是当我构建调试版本时,出现以下错误
CMake Error at cmake_install.cmake:55 (file):
file INSTALL cannot find
"<my project's root>/build/Release/math.lib".
为什么尽管我为调试构建,但它仍在发布文件夹中查找? 当我为发布而构建时,显然,一切正常。 我试图CONFIGURATIONS
选项添加到install
方法中,但它没有帮助。 我正在使用Visual Studio 15。
如果我查看我的cmake_install.cmake
,如果您未在add_custom_command()
调用中指定任何内容,则Release
是默认值:
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "Release")
endif()
message(STATUS "Install configuration: "${CMAKE_INSTALL_CONFIG_NAME}"")
endif()
因此,如果您查看INSTALL.vcxproj
CMake 生成的调用如下所示:
"C:Program FilesCMakebincmake.exe" -DBUILD_TYPE=$(Configuration) -P cmake_install.cmake
这将转化为:
add_custom_command(TARGET math
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -D BUILD_TYPE=$<CONFIG> -P cmake_install.cmake)