为什么cmake install()在VS的Release文件夹中查找输出文件

时间:2018-05-20 11:35:28

标签: visual-studio cmake install targets

这是我的cmake的简化版

class Foo {
public:
   Foo() ;
   int& getFoo() {return myFoo;} 
private:
   int myFoo;
};

但是当我构建Debug版本时,我收到以下错误

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()

为什么它在Release文件夹中查看尽管我为Debug构建? 当我为Release构建时,很明显,一切正常。 我尝试将CMake Error at cmake_install.cmake:55 (file): file INSTALL cannot find "<my project's root>/build/Release/math.lib". 选项添加到CONFIGURATIONS方法,但它没有帮助。 我正在使用Visual Studio 15。

1 个答案:

答案 0 :(得分:1)

如果我查看我的cmake_install.cmakeRelease是默认设置,如果您未在add_custom_command()电话中指定任何内容:

# 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 Files\CMake\bin\cmake.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)