VS: WINDOWS_EXPORT_ALL_SYMBOL does not work with source in per-$<CONFIG> directory
- When generating file in a unique path to
$<CONFIG>
, and enabling WINDOWS_EXPORT_ALL_SYMBOL, MSVC errors for missing object file, when using Visual Studio 2019 generator. - When using Ninja Multi-Config, no errors.
- When using Unix Makefiles, no errors.
Minimum Example:
CMakeLists.txt
cmake_minimum_required(VERSION 3.26)
project(vs_gen_test)
set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_sources_$<CONFIG>")
set(GEN_SRC "${GEN_DIR}/gen_src.cxx")
add_custom_command(
OUTPUT "${GEN_SRC}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${GEN_DIR}"
COMMAND "${CMAKE_COMMAND}" -E touch "${GEN_SRC}"
)
add_library(
lib
SHARED
"${GEN_SRC}"
)
set_target_properties(
lib
PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
CMake Build Log Using Visual Studio 2019:
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Generating generated_sources_Debug/gen_src.cxx
Building Custom Rule <path>/vs_gen_export_issue/CMakeLists.txt
gen_src.cxx
Auto build dll exports
Couldn't open file '<path>/vs_gen_export_issue/build-vs2019/lib.dir/Debug/gen_src.obj' with CreateFile()
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: The command "setlocal [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: cd <path>\vs_gen_export_issue\build-vs2019 [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: C: [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -E __create_def <path>/vs_gen_export_issue/build-vs2019/lib.dir/Debug/exports.def <path>/vs_gen_export_issue/build-vs2019/lib.dir/Debug//objects.txt [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: :cmEnd [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: :cmErrorLevel [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: exit /b %1 [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: :cmDone [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(150,5): error MSB3073: :VCEnd" exited with code 1. [<path>\vs_gen_export_issue\build-vs2019\lib.vcxproj]
Edited by Brad King