In the example below, I would expect the everything (MyExecutable.exe, CommandLine.dll, MyLibrary.dll and Newtonsoft.Json.dll) to be installed to bin (i.e. CMAKE_INSTALL_BINDIR). I observe the following (output pasted below the example):
- Correct:
MyExecutable.exeis installed tobinMyLibrary.dllis installed tobin
- Unexpected:
MyLibrary.dlladditionally installed tolib. Not sure if it is intended for*.pdbis supposed to be installed or notNewtonsoft.Json.dllinstalled tolibinstead ofbinCommandLine.dllnot installed at all
I recognize that I would work around by setting the install DESTINATION and use install(FILES) for the missing things. I posted this as an issue here, but it was not conclusively accepted so I ask this forum to weigh in. Thanks
# Top Level CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(InstallDemo LANGUAGES CSharp)
add_subdirectory(bin)
add_subdirectory(lib)
# lib/CMakeLists.txt
# Library with NuGet dependency
add_library(MyLibrary SHARED)
target_sources(MyLibrary PRIVATE
Library.cs
)
set_target_properties(MyLibrary PROPERTIES
VS_PACKAGE_REFERENCES "Newtonsoft.Json_13.0.3"
)
install(TARGETS MyLibrary)
# bin/CMakeLists.txt
# Executable that depends on the library AND has its own NuGet dependency
add_executable(MyApp)
target_sources(MyApp PRIVATE
Program.cs
)
target_link_libraries(MyApp PRIVATE MyLibrary)
set_target_properties(MyApp PROPERTIES
VS_PACKAGE_REFERENCES "CommandLineParser_2.9.1"
)
install(TARGETS MyApp)
Example console output
kevinyee@NM0107 MINGW64 ~/csharp_install
$ cmake -B build
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.26200.
-- The CSharp compiler identification is Microsoft Visual Studio 2019
-- The CSharp compiler version is 3.11.0
-- Check for working C# compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/Roslyn/csc.exe
-- Check for working C# compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/Roslyn/csc.exe - works
-- Configuring done (2.1s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/kevinyee/csharp_install/build
kevinyee@NM0107 MINGW64 ~/csharp_install
$ cmake --build build
Microsoft (R) Build Engine version 16.11.6+a918ceb31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored C:\Users\kevinyee\csharp_install\build\lib\MyLibrary.csproj (in 382 ms).
Restored C:\Users\kevinyee\csharp_install\build\bin\MyApp.csproj (in 382 ms).
1>Checking Build System
MyLibrary -> C:\Users\kevinyee\csharp_install\build\lib\Debug\MyLibrary.dll
MyApp -> C:\Users\kevinyee\csharp_install\build\bin\Debug\MyApp.exe
Building Custom Rule C:/Users/kevinyee/csharp_install/CMakeLists.txt
kevinyee@NM0107 MINGW64 ~/csharp_install
$ cmake --install build --prefix install --config Debug
-- Installing: C:/Users/kevinyee/csharp_install/install/bin/MyApp.exe
-- Up-to-date: C:/Users/kevinyee/csharp_install/install/lib
-- Installing: C:/Users/kevinyee/csharp_install/install/lib/MyLibrary.dll
-- Installing: C:/Users/kevinyee/csharp_install/install/lib/MyLibrary.pdb
-- Installing: C:/Users/kevinyee/csharp_install/install/lib/Newtonsoft.Json.dll
-- Installing: C:/Users/kevinyee/csharp_install/install/bin/MyLibrary.dll