Post 使用 CMake 构建 project.sln 时构建事件错误
Post build event error when building project.sln with CMake
我的任务是将大型框架转换并构建为 CMake 树和二进制文件。目前,该框架是使用 VS 2017 构建的,创建了一个名为 Framework_static_vc15.sln 的解决方案。由于这是一个大型项目,我选择使用转换器为该项目的每个部分创建 CMakeLists.txt 文件。这是我使用的转换器的link。
https://cmakeconverter.readthedocs.io/en/develop/intro.html
此转换器成功创建了所有需要的文本文件,我可以 运行 命令
cmake -S . -B build
要创建一个我应该可以 运行 cmake --build build
的目录。
但是,当我 运行 上面的命令时,构建每次都失败并出现以下错误
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: The command "setlocal [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcx
proj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: cd C:\Work\SVN\Software\Framework\Source\UeiDaqCore [C:\Work\SVN\Software\Framework\build\Source\
UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: C: [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib [C:\Work\SVN\Software\Framework\build\Source\UeiDa
qCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: copy C:\Work\SVN\Software\Framework\Source\UeiDaqCore\..\..\Output\Win32\vs15_DebugUeiDaqvc15SD.l
ib ..\..\CPP\lib [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: cd. [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: cd. [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone [C:\Work\SVN\Software\Framework\build\S
ource\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: :cmErrorLevel [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: exit /b %1 [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: :cmDone [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: :VCEnd" exited with code 1. [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc
15.vcxproj]
此错误来自名为 UeiDaqCore 的子项目中的 post 构建事件,该事件在 CMake 尝试执行以下命令时出现 UeiDaqCore_vc15.vcxproj -> C:\Work\SVN\Software\Framework\Output\Win32\vs15_Debug\UeiDaqCore_vc15SD.lib
。 CMake 给了我没有所有路径的错误列表,就在这里。
PostBuildEvent:
setlocal
cd C:\Work\SVN\Software\Framework\Source\UeiDaqCore
if %errorlevel% neq 0 goto :cmEnd
C:
if %errorlevel% neq 0 goto :cmEnd
if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
if %errorlevel% neq 0 goto :cmEnd
copy C:\Work\SVN\Software\Framework\Source\UeiDaqCore\..\..\Output\Win32\vs15_DebugUeiDaqvc15SD.lib ..\..\CPP\lib
if %errorlevel% neq 0 goto :cmEnd
cd.
if %errorlevel% neq 0 goto :cmEnd
cd.
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd
The system cannot find the file specified.
我查看了 Visual Studio UeiDaqCore 项目文件中的 post 个名为 setlocal
的构建事件,我还查看了 CmakeLists.txt 文件中的 setlocal
post 构建事件,但可以找到 none。
从错误文本来看,它似乎正在寻找一个名为 UeiDaqCore_vc15.vcxproj
的项目和一个名为 UeiDaqCore_vc15SD.lib
的文件,但找不到。我不确定为什么,因为这两个文件都位于它查找的文件夹中。
我正在 运行使用管理员命令提示符设置 CMake,因为我看到其他人遇到过这个问题,这是由于没有管理员权限造成的。在此之下,我将 post UeiDaqCore 子项目的完整 CmakeLists.txt。
project(UeiDaqCore_vc15 CXX)
################################################################################
# Source groups
################################################################################
set(no_group_source_files
ReadMe.txt
)
source_group("" FILES ${no_group_source_files})
set(Headers
../../CPP/include/UeiChannel.h
../../CPP/include/UeiConstants.h
../../CPP/include/UeiCustomScale.h
../../CPP/include/UeiDaq.h
../../CPP/include/UeiDaqAnsiC.h
../../CPP/include/UeiDaqError.h
../../CPP/include/UeiDataStream.h
../../CPP/include/UeiDevice.h
../../CPP/include/UeiDeviceEnumerator.h
../../CPP/include/UeiDriverEnumerator.h
../../CPP/include/UeiEvent.h
../../CPP/include/UeiException.h
../../CPP/include/UeiFrameUtils.h
../../CPP/include/UeiMessaging.h
../../CPP/include/UeiObject.h
../../CPP/include/UeiReader.h
../../CPP/include/UeiResourceParser.h
../../CPP/include/UeiSession.h
../../CPP/include/UeiSessionGroup.h
../../CPP/include/UeiStructs.h
../../CPP/include/Ueisystem.h
../../CPP/include/UeiTiming.h
../../CPP/include/UeiTrigger.h
../../CPP/include/UeiWriter.h
pugxml.h
resource.h
ResourceParser.h
SensorConversion.h
SignalParser.h
StdAfx.h
UeiAnsiCSession.h
UeiChannelimpl.h
UeiCJCConverter.h
UeiDaqCore.h
UeiDaqCoreVer.h
UeiDaqDriver.h
UeiDaqDriverSession.h
UeiDaqLV.h
UeiDataStreamImpl.h
UeiDeviceEnumeratorImpl.h
UeiDeviceImpl.h
UeiDriverEvent.h
UeiMessagingImpl.h
UeiObjectImpl.h
UeiReaderImpl.h
UeiRTDConverter.h
UeiSessionImpl.h
UeiSessionSettings.h
UeiTimingImpl.h
UeiTriggerImpl.h
UeiWriterImpl.h
UeiXmlParser.h
)
source_group("Headers" FILES ${Headers})
set(Sources
ResourceParser.cpp
SensorConversion.cpp
StdAfx.cpp
UeiChannel.cpp
UeiChannelImpl.cpp
UeiCJCConverter.cpp
UeiCustomScale.cpp
UeiDaqAnsiC.cpp
UeiDaqCore.cpp
UeiDaqLV.cpp
UeiDataStream.cpp
UeiDataStreamImpl.cpp
UeiDevice.cpp
UeiDeviceEnumerator.cpp
UeiDeviceEnumeratorImpl.cpp
UeiDeviceImpl.cpp
UeiDriverEnumerator.cpp
UeiException.cpp
UeiFrameUtils.cpp
UeiMessaging.cpp
UeiMessagingImpl.cpp
UeiObject.cpp
UeiObjectImpl.cpp
UeiReader.cpp
UeiReaderImpl.cpp
UeiResourceParser.cpp
UeiRTDConverter.cpp
UeiSession.cpp
UeiSessionGroup.cpp
UeiSessionImpl.cpp
UeiSessionSettings.cpp
UeiSystem.cpp
UeiTiming.cpp
UeiTimingImpl.cpp
UeiTrigger.cpp
UeiTriggerImpl.cpp
UeiWriter.cpp
UeiWriterImpl.cpp
UeiXmlParser.cpp
)
source_group("Sources" FILES ${Sources})
set(ALL_FILES
${no_group_source_files}
${Headers}
${Sources}
)
################################################################################
# Target
################################################################################
add_library(${PROJECT_NAME} STATIC ${ALL_FILES})
add_precompiled_header(${PROJECT_NAME} "StdAfx.h" "StdAfx.cpp")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
set(ROOT_NAMESPACE UeiDaqCore)
################################################################################
# Target name
################################################################################
set_target_properties(${PROJECT_NAME} PROPERTIES
TARGET_NAME_DEBUG "${PROJECT_NAME}SD"
TARGET_NAME_RELEASE "${PROJECT_NAME}S"
)
################################################################################
# Output directory
################################################################################
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../../Output/${CMAKE_VS_PLATFORM_NAME}/vs15_$<CONFIG>"
OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../Output/${CMAKE_VS_PLATFORM_NAME}/vs15_$<CONFIG>"
)
################################################################################
# Include directories
################################################################################
target_include_directories(${PROJECT_NAME} PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/../../CPP/include;"
"$ENV{UEICOMMON}/includes"
)
################################################################################
# Compile definitions
################################################################################
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG;"
"UEIDAQ_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"WIN32;"
"_WINDOWS;"
"UEIDAQSTATIC;"
"__MSWINDOWS__;"
"_MBCS"
)
set_source_files_properties(ResourceParser.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(StdAfx.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;UEIDAQSTATIC"
)
set_source_files_properties(UeiChannel.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiChannelImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDaqCore.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDataStream.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDataStreamImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDevice.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDeviceEnumerator.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDeviceEnumeratorImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDeviceImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiException.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiObject.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiObjectImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiSession.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiSessionGroup.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiSessionImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiTiming.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiTimingImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiTrigger.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiTriggerImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
################################################################################
# Compile and link options
################################################################################
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/Od;
/RTC1;
/MTd
>
$<$<CONFIG:Release>:
/O2;
/Ob1;
/GF;
/MT;
/Gy
>
/W3;
/nologo;
/Zi;
/GR;
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(ResourceParser.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(StdAfx.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiChannel.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiChannelImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDaqCore.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDataStream.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDataStreamImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDevice.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDeviceEnumerator.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDeviceEnumeratorImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDeviceImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiException.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiObject.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiObjectImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiSession.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiSessionGroup.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiSessionImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiTiming.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiTimingImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiTrigger.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiTriggerImpl.cpp ${FILE_CL_OPTIONS})
endif()
################################################################################
# Post build events
################################################################################
add_custom_command_if(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMANDS
COMMAND $<CONFIG:Debug> if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
COMMAND $<CONFIG:Debug> copy $<SHELL_PATH:${OUTPUT_DIRECTORY}>UeiDaqvc15SD.lib ..\..\CPP\lib
COMMAND $<CONFIG:Release> if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
COMMAND $<CONFIG:Release> copy $<SHELL_PATH:${OUTPUT_DIRECTORY}>UeiDaqvc15S.lib ..\..\CPP\lib
)
################################################################################
# Dependencies
################################################################################
add_dependencies(${PROJECT_NAME}
UeiPDNADriver_vc15
UeiSimuDriver_vc15
)
# Link with other targets.
target_link_libraries(${PROJECT_NAME} PUBLIC
UeiPDNADriver_vc15
UeiSimuDriver_vc15
)
我是 CMake 的新手,任何对可能的解决方案的帮助都将不胜感激。
编辑:这是直接从 Visual Studio window.
复制的 UeiDaqCore 的 post 构建事件
copy "$(SolutionDir)\Output$(Platform)\vs15_$(Configuration)\UeiDaqvc15D.dll" "$(SystemRoot)\System32"
if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
copy "$(SolutionDir)\Output$(Platform)\vs15_$(Configuration)\UeiDaqvc15D.lib" ..\..\CPP\lib
看起来 POST_BUILD
自定义命令格式不正确。具体来说,copy
命令没有在定义的 OUTPUT_DIRECTORY
:
之间放置路径分隔符
C:\Work\SVN\Software\Framework\Source\UeiDaqCore\..\..\Output\Win32\vs15_Debug
来自文件名:
UeiDaqvc15SD.lib
所以他们被(错误地)连接起来:
C:\Work\SVN\Software\Framework\Source\UeiDaqCore\..\..\Output\Win32\vs15_DebugUeiDaqvc15SD.lib
尝试在 $<SHELL_PATH:${OUTPUT_DIRECTORY}>
:
之后的自定义命令中添加路径分隔符 \
add_custom_command_if(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMANDS
COMMAND $<CONFIG:Debug> if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
COMMAND $<CONFIG:Debug> copy $<SHELL_PATH:${OUTPUT_DIRECTORY}>\UeiDaqvc15SD.lib ..\..\CPP\lib
COMMAND $<CONFIG:Release> if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
COMMAND $<CONFIG:Release> copy $<SHELL_PATH:${OUTPUT_DIRECTORY}>\UeiDaqvc15S.lib ..\..\CPP\lib
)
我的任务是将大型框架转换并构建为 CMake 树和二进制文件。目前,该框架是使用 VS 2017 构建的,创建了一个名为 Framework_static_vc15.sln 的解决方案。由于这是一个大型项目,我选择使用转换器为该项目的每个部分创建 CMakeLists.txt 文件。这是我使用的转换器的link。
https://cmakeconverter.readthedocs.io/en/develop/intro.html
此转换器成功创建了所有需要的文本文件,我可以 运行 命令
cmake -S . -B build
要创建一个我应该可以 运行 cmake --build build
的目录。
但是,当我 运行 上面的命令时,构建每次都失败并出现以下错误
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: The command "setlocal [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcx
proj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: cd C:\Work\SVN\Software\Framework\Source\UeiDaqCore [C:\Work\SVN\Software\Framework\build\Source\
UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: C: [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib [C:\Work\SVN\Software\Framework\build\Source\UeiDa
qCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: copy C:\Work\SVN\Software\Framework\Source\UeiDaqCore\..\..\Output\Win32\vs15_DebugUeiDaqvc15SD.l
ib ..\..\CPP\lib [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: cd. [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: cd. [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: :cmEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone [C:\Work\SVN\Software\Framework\build\S
ource\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: :cmErrorLevel [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: exit /b %1 [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: :cmDone [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqC
ore_vc15.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
38,5): error MSB3073: :VCEnd" exited with code 1. [C:\Work\SVN\Software\Framework\build\Source\UeiDaqCore\UeiDaqCore_vc
15.vcxproj]
此错误来自名为 UeiDaqCore 的子项目中的 post 构建事件,该事件在 CMake 尝试执行以下命令时出现 UeiDaqCore_vc15.vcxproj -> C:\Work\SVN\Software\Framework\Output\Win32\vs15_Debug\UeiDaqCore_vc15SD.lib
。 CMake 给了我没有所有路径的错误列表,就在这里。
PostBuildEvent:
setlocal
cd C:\Work\SVN\Software\Framework\Source\UeiDaqCore
if %errorlevel% neq 0 goto :cmEnd
C:
if %errorlevel% neq 0 goto :cmEnd
if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
if %errorlevel% neq 0 goto :cmEnd
copy C:\Work\SVN\Software\Framework\Source\UeiDaqCore\..\..\Output\Win32\vs15_DebugUeiDaqvc15SD.lib ..\..\CPP\lib
if %errorlevel% neq 0 goto :cmEnd
cd.
if %errorlevel% neq 0 goto :cmEnd
cd.
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd
The system cannot find the file specified.
我查看了 Visual Studio UeiDaqCore 项目文件中的 post 个名为 setlocal
的构建事件,我还查看了 CmakeLists.txt 文件中的 setlocal
post 构建事件,但可以找到 none。
从错误文本来看,它似乎正在寻找一个名为 UeiDaqCore_vc15.vcxproj
的项目和一个名为 UeiDaqCore_vc15SD.lib
的文件,但找不到。我不确定为什么,因为这两个文件都位于它查找的文件夹中。
我正在 运行使用管理员命令提示符设置 CMake,因为我看到其他人遇到过这个问题,这是由于没有管理员权限造成的。在此之下,我将 post UeiDaqCore 子项目的完整 CmakeLists.txt。
project(UeiDaqCore_vc15 CXX)
################################################################################
# Source groups
################################################################################
set(no_group_source_files
ReadMe.txt
)
source_group("" FILES ${no_group_source_files})
set(Headers
../../CPP/include/UeiChannel.h
../../CPP/include/UeiConstants.h
../../CPP/include/UeiCustomScale.h
../../CPP/include/UeiDaq.h
../../CPP/include/UeiDaqAnsiC.h
../../CPP/include/UeiDaqError.h
../../CPP/include/UeiDataStream.h
../../CPP/include/UeiDevice.h
../../CPP/include/UeiDeviceEnumerator.h
../../CPP/include/UeiDriverEnumerator.h
../../CPP/include/UeiEvent.h
../../CPP/include/UeiException.h
../../CPP/include/UeiFrameUtils.h
../../CPP/include/UeiMessaging.h
../../CPP/include/UeiObject.h
../../CPP/include/UeiReader.h
../../CPP/include/UeiResourceParser.h
../../CPP/include/UeiSession.h
../../CPP/include/UeiSessionGroup.h
../../CPP/include/UeiStructs.h
../../CPP/include/Ueisystem.h
../../CPP/include/UeiTiming.h
../../CPP/include/UeiTrigger.h
../../CPP/include/UeiWriter.h
pugxml.h
resource.h
ResourceParser.h
SensorConversion.h
SignalParser.h
StdAfx.h
UeiAnsiCSession.h
UeiChannelimpl.h
UeiCJCConverter.h
UeiDaqCore.h
UeiDaqCoreVer.h
UeiDaqDriver.h
UeiDaqDriverSession.h
UeiDaqLV.h
UeiDataStreamImpl.h
UeiDeviceEnumeratorImpl.h
UeiDeviceImpl.h
UeiDriverEvent.h
UeiMessagingImpl.h
UeiObjectImpl.h
UeiReaderImpl.h
UeiRTDConverter.h
UeiSessionImpl.h
UeiSessionSettings.h
UeiTimingImpl.h
UeiTriggerImpl.h
UeiWriterImpl.h
UeiXmlParser.h
)
source_group("Headers" FILES ${Headers})
set(Sources
ResourceParser.cpp
SensorConversion.cpp
StdAfx.cpp
UeiChannel.cpp
UeiChannelImpl.cpp
UeiCJCConverter.cpp
UeiCustomScale.cpp
UeiDaqAnsiC.cpp
UeiDaqCore.cpp
UeiDaqLV.cpp
UeiDataStream.cpp
UeiDataStreamImpl.cpp
UeiDevice.cpp
UeiDeviceEnumerator.cpp
UeiDeviceEnumeratorImpl.cpp
UeiDeviceImpl.cpp
UeiDriverEnumerator.cpp
UeiException.cpp
UeiFrameUtils.cpp
UeiMessaging.cpp
UeiMessagingImpl.cpp
UeiObject.cpp
UeiObjectImpl.cpp
UeiReader.cpp
UeiReaderImpl.cpp
UeiResourceParser.cpp
UeiRTDConverter.cpp
UeiSession.cpp
UeiSessionGroup.cpp
UeiSessionImpl.cpp
UeiSessionSettings.cpp
UeiSystem.cpp
UeiTiming.cpp
UeiTimingImpl.cpp
UeiTrigger.cpp
UeiTriggerImpl.cpp
UeiWriter.cpp
UeiWriterImpl.cpp
UeiXmlParser.cpp
)
source_group("Sources" FILES ${Sources})
set(ALL_FILES
${no_group_source_files}
${Headers}
${Sources}
)
################################################################################
# Target
################################################################################
add_library(${PROJECT_NAME} STATIC ${ALL_FILES})
add_precompiled_header(${PROJECT_NAME} "StdAfx.h" "StdAfx.cpp")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
set(ROOT_NAMESPACE UeiDaqCore)
################################################################################
# Target name
################################################################################
set_target_properties(${PROJECT_NAME} PROPERTIES
TARGET_NAME_DEBUG "${PROJECT_NAME}SD"
TARGET_NAME_RELEASE "${PROJECT_NAME}S"
)
################################################################################
# Output directory
################################################################################
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../../Output/${CMAKE_VS_PLATFORM_NAME}/vs15_$<CONFIG>"
OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../Output/${CMAKE_VS_PLATFORM_NAME}/vs15_$<CONFIG>"
)
################################################################################
# Include directories
################################################################################
target_include_directories(${PROJECT_NAME} PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/../../CPP/include;"
"$ENV{UEICOMMON}/includes"
)
################################################################################
# Compile definitions
################################################################################
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG;"
"UEIDAQ_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"WIN32;"
"_WINDOWS;"
"UEIDAQSTATIC;"
"__MSWINDOWS__;"
"_MBCS"
)
set_source_files_properties(ResourceParser.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(StdAfx.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;UEIDAQSTATIC"
)
set_source_files_properties(UeiChannel.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiChannelImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDaqCore.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDataStream.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDataStreamImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDevice.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDeviceEnumerator.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDeviceEnumeratorImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiDeviceImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiException.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiObject.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiObjectImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiSession.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiSessionGroup.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiSessionImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiTiming.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiTimingImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiTrigger.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
set_source_files_properties(UeiTriggerImpl.cpp PROPERTIES
COMPILE_DEFINITIONS_DEBUG "_DEBUG"
COMPILE_DEFINITIONS_RELEASE "NDEBUG"
COMPILE_DEFINITIONS "WIN32;_WINDOWS;_MBCS;_USRDLL;UEIDAQCORE_EXPORTS"
)
################################################################################
# Compile and link options
################################################################################
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/Od;
/RTC1;
/MTd
>
$<$<CONFIG:Release>:
/O2;
/Ob1;
/GF;
/MT;
/Gy
>
/W3;
/nologo;
/Zi;
/GR;
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(ResourceParser.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(StdAfx.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiChannel.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiChannelImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDaqCore.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDataStream.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDataStreamImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDevice.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDeviceEnumerator.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDeviceEnumeratorImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiDeviceImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiException.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiObject.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiObjectImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiSession.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiSessionGroup.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiSessionImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiTiming.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiTimingImpl.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiTrigger.cpp ${FILE_CL_OPTIONS})
string(CONCAT FILE_CL_OPTIONS
"$<$<CONFIG:Debug>:"
"/Od;/RTC1"
">"
"$<$<CONFIG:Release>:"
"/O2"
">"
)
source_file_compile_options(UeiTriggerImpl.cpp ${FILE_CL_OPTIONS})
endif()
################################################################################
# Post build events
################################################################################
add_custom_command_if(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMANDS
COMMAND $<CONFIG:Debug> if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
COMMAND $<CONFIG:Debug> copy $<SHELL_PATH:${OUTPUT_DIRECTORY}>UeiDaqvc15SD.lib ..\..\CPP\lib
COMMAND $<CONFIG:Release> if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
COMMAND $<CONFIG:Release> copy $<SHELL_PATH:${OUTPUT_DIRECTORY}>UeiDaqvc15S.lib ..\..\CPP\lib
)
################################################################################
# Dependencies
################################################################################
add_dependencies(${PROJECT_NAME}
UeiPDNADriver_vc15
UeiSimuDriver_vc15
)
# Link with other targets.
target_link_libraries(${PROJECT_NAME} PUBLIC
UeiPDNADriver_vc15
UeiSimuDriver_vc15
)
我是 CMake 的新手,任何对可能的解决方案的帮助都将不胜感激。
编辑:这是直接从 Visual Studio window.
复制的 UeiDaqCore 的 post 构建事件copy "$(SolutionDir)\Output$(Platform)\vs15_$(Configuration)\UeiDaqvc15D.dll" "$(SystemRoot)\System32"
if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
copy "$(SolutionDir)\Output$(Platform)\vs15_$(Configuration)\UeiDaqvc15D.lib" ..\..\CPP\lib
看起来 POST_BUILD
自定义命令格式不正确。具体来说,copy
命令没有在定义的 OUTPUT_DIRECTORY
:
C:\Work\SVN\Software\Framework\Source\UeiDaqCore\..\..\Output\Win32\vs15_Debug
来自文件名:
UeiDaqvc15SD.lib
所以他们被(错误地)连接起来:
C:\Work\SVN\Software\Framework\Source\UeiDaqCore\..\..\Output\Win32\vs15_DebugUeiDaqvc15SD.lib
尝试在 $<SHELL_PATH:${OUTPUT_DIRECTORY}>
:
\
add_custom_command_if(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMANDS
COMMAND $<CONFIG:Debug> if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
COMMAND $<CONFIG:Debug> copy $<SHELL_PATH:${OUTPUT_DIRECTORY}>\UeiDaqvc15SD.lib ..\..\CPP\lib
COMMAND $<CONFIG:Release> if not exist ..\..\CPP\lib mkdir ..\..\CPP\lib
COMMAND $<CONFIG:Release> copy $<SHELL_PATH:${OUTPUT_DIRECTORY}>\UeiDaqvc15S.lib ..\..\CPP\lib
)