CMake语法以安装自定义生成的文件

时间:2019-06-04 08:14:52

标签: visual-studio cmake

我正在尝试使以下cmake代码段能够处理用户从cpack窗口调用cmd的情况(而不是在Visual Studio中,单击“ PACKAGE”目标)。当前它失败并显示:

c:\tmp>cpack.exe -G ZIP
CPack: Create package using ZIP
CPack: Install projects
CPack: - Install project: GDCM
CMake Error at C:/tmp/gdcm-swig-x64/Wrapping/Csharp/cmake_install.cmake:60 (file):
  file INSTALL cannot find
  "C:/tmp/gdcm-swig-x64/bin//gdcm-sharp.dll".
Call Stack (most recent call first):
  C:/tmp/gdcm-swig-x64/cmake_install.cmake:51 (include
)

CPack Error: Error when generating package: GDCM

当前代码的灵感来自here。就像(full code):

set(GDCM_LIBRARY_DIR2 ${LIBRARY_OUTPUT_PATH}/\${BUILD_TYPE})
install(FILES ${GDCM_LIBRARY_DIR2}/gdcm_csharp.dll
  DESTINATION ${GDCM_INSTALL_LIB_DIR} COMPONENT Runtime
)

其中gdcm_csharp.dll是通过add_custom_command生成的,例如:

add_custom_command(
  OUTPUT ${GDCM_LIBRARY_DIR}/gdcm_csharp.dll
  COMMAND ${CMAKE_CSHARP_COMPILER} ARGS "/t:library" "/out:${GDCM_LIBRARY_DIR}/gdcm_csharp.dll" "*.cs"
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  DEPENDS "${swig_generated_file_fullname}" ${CMAKE_CURRENT_BINARY_DIR}/AssemblyInfo.cs
  COMMENT "csc *.cs"
)

是否有一种方法可以修复install(FILES) command来处理两种情况(在Visual Studio内和外部)?

1 个答案:

答案 0 :(得分:0)

要在不显式运行Visual Studio的情况下执行PACKAGE目标,可以执行以下操作:

cmake --build C:/tmp/gdcm-swig-x64/ --config Release --target PACKAGE