title: Post build event error when building project.sln with CMake
body: <p>I've been tasked with converting and building a large framework into a CMake tree and binary. Currently, the framework is built using VS 2017, creating a solution named Framework_static_vc15.sln. As this is a large project, I opted to use a converter to create the CMakeLists.txt files for each part of this project. Here is the link to the converter I used.</p>
  
  <p><a href="https://cmakeconverter.readthedocs.io/en/develop/intro.html" rel="nofollow noreferrer">https://cmakeconverter.readthedocs.io/en/develop/intro.html</a></p>
  
  <p>This converter successfully creates all the text files needed, and I can run the command </p>
  
  <pre><code>cmake -S . -B build
  </code></pre>
  
  <p>To create a directory that I should be able to run <code>cmake --build build</code> on.
  However, when I run the above command, the build fails every time with the following error</p>
  
  <pre><code>C:\Program Files (x86)\Microsoft Visual Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(1
  38,5): error MSB3073: endlocal &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone [C:\Work\SVN\Software\Framework\build\S
  ource\UeiDaqCore\UeiDaqCore_vc15.vcxproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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 Studio\2017\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]
  </code></pre>
  
  <p>This error is from a post build event inside a sub-project named UeiDaqCore, that arises when CMake tries to execute the following command <code>UeiDaqCore_vc15.vcxproj -&gt; C:\Work\SVN\Software\Framework\Output\Win32\vs15_Debug\UeiDaqCore_vc15SD.lib</code>. CMake gives me the error list without all the paths, and here it is.</p>
  
  <pre><code>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 &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone
    :cmErrorLevel
    exit /b %1
    :cmDone
    if %errorlevel% neq 0 goto :VCEnd
    :VCEnd
    The system cannot find the file specified.
  </code></pre>
  
  <p>I looked through the Visual Studio UeiDaqCore project file for post build events named <code>setlocal</code>, and I also looked through the CmakeLists.txt files for <code>setlocal</code> post build events, but could find none. 
  From the error text, it looks like it's looking for a project named <code>UeiDaqCore_vc15.vcxproj</code> and a file named <code>UeiDaqCore_vc15SD.lib</code>, but cant find it. I'm not sure why, because both files are located in the folder its looking in.</p>
  
  <p>I am running CMake with the administrator command prompt, as I've seen others who have had this problem, and it was caused by no admin privileges. Below this, I'll post the full CmakeLists.txt for the UeiDaqCore subproject.</p>
  
  <pre><code>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_$&lt;CONFIG&gt;"
      OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../Output/${CMAKE_VS_PLATFORM_NAME}/vs15_$&lt;CONFIG&gt;"
  )
  ################################################################################
  # 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
      "$&lt;$&lt;CONFIG:Debug&gt;:"
          "_DEBUG;"
          "UEIDAQ_DEBUG"
      "&gt;"
      "$&lt;$&lt;CONFIG:Release&gt;:"
          "NDEBUG"
      "&gt;"
      "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
          $&lt;$&lt;CONFIG:Debug&gt;:
              /Od;
              /RTC1;
              /MTd
          &gt;
          $&lt;$&lt;CONFIG:Release&gt;:
              /O2;
              /Ob1;
              /GF;
              /MT;
              /Gy
          &gt;
          /W3;
          /nologo;
          /Zi;
          /GR;
          ${DEFAULT_CXX_EXCEPTION_HANDLING}
      )
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(ResourceParser.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(StdAfx.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiChannel.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiChannelImpl.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiDaqCore.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiDataStream.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiDataStreamImpl.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiDevice.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiDeviceEnumerator.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiDeviceEnumeratorImpl.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiDeviceImpl.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiException.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiObject.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiObjectImpl.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiSession.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiSessionGroup.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiSessionImpl.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiTiming.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiTimingImpl.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiTrigger.cpp ${FILE_CL_OPTIONS})
      string(CONCAT FILE_CL_OPTIONS
          "$&lt;$&lt;CONFIG:Debug&gt;:"
              "/Od;/RTC1"
          "&gt;"
          "$&lt;$&lt;CONFIG:Release&gt;:"
              "/O2"
          "&gt;"
      )
      source_file_compile_options(UeiTriggerImpl.cpp ${FILE_CL_OPTIONS})
  endif()
  
  ################################################################################
  # Post build events
  ################################################################################
  add_custom_command_if(
      TARGET ${PROJECT_NAME}
      POST_BUILD
      COMMANDS
      COMMAND   $&lt;CONFIG:Debug&gt; if not exist ..\\..\\CPP\\lib mkdir ..\\..\\CPP\\lib
      COMMAND   $&lt;CONFIG:Debug&gt; copy $&lt;SHELL_PATH:${OUTPUT_DIRECTORY}&gt;UeiDaqvc15SD.lib ..\\..\\CPP\\lib
      COMMAND $&lt;CONFIG:Release&gt; if not exist ..\\..\\CPP\\lib mkdir ..\\..\\CPP\\lib
      COMMAND $&lt;CONFIG:Release&gt; copy $&lt;SHELL_PATH:${OUTPUT_DIRECTORY}&gt;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
  )
  
  </code></pre>
  
  <p>I'm quite new to CMake, and any help towards a possible solution would be appreciated. </p>
  
  <p>EDIT: Here are the post build events for UeiDaqCore copied directly from the Visual Studio window.</p>
  
  <pre><code>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
  </code></pre>