diff --git a/CMakeLists.txt b/CMakeLists.txt index 27765fd1c..182bd9d0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,14 @@ cmake_minimum_required(VERSION 3.11) -project(WIL) + +project(WIL + VERSION 0.0.0.0 + DESCRIPTION "The Windows Implementation Libraries (wil) were created to improve productivity and solve problems commonly seen by Windows developers." + HOMEPAGE_URL "https://github.com/Microsoft/wil" + LANGUAGES CXX) # Set by build server to speed up build/reduce file/object size option(FAST_BUILD "Sets options to speed up build/reduce obj/executable size" OFF) -if (NOT DEFINED WIL_BUILD_VERSION) - set(WIL_BUILD_VERSION "0.0.0") -endif() - # Detect the Windows SDK version. If we're using the Visual Studio generator, this will be provided for us. Otherwise # we'll need to assume that this value comes from the command line (e.g. through the VS command prompt) if (DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) @@ -17,5 +18,63 @@ else() string(REGEX REPLACE "\\\\$" "" WIL_WINDOWS_SDK_VERSION "$ENV{WindowsSDKVersion}") endif() -add_subdirectory(packaging) +add_library(WIL INTERFACE) + +target_include_directories(WIL + INTERFACE + "$" + "$") + +install( + DIRECTORY "include/" + DESTINATION "include") + +install( + FILES "ThirdPartyNotices.txt" + DESTINATION ".") + +# Export the targets for consumption by other CMake projects + +include(CMakePackageConfigHelpers) + +configure_package_config_file( + "cmake/WILConfig.cmake.in" + "${CMAKE_BINARY_DIR}/cmake/WILConfig.cmake" + INSTALL_DESTINATION "cmake") + +write_basic_package_version_file( + "${CMAKE_BINARY_DIR}/cmake/WILConfigVersion.cmake" + COMPATIBILITY ExactVersion ARCH_INDEPENDENT) + +install( + FILES + "${CMAKE_BINARY_DIR}/cmake/WILConfig.cmake" + "${CMAKE_BINARY_DIR}/cmake/WILConfigVersion.cmake" + DESTINATION "cmake") + +export(TARGETS WIL FILE "cmake/WILTargets.cmake") + +install(TARGETS WIL EXPORT WILTargets) +install(EXPORT WILTargets DESTINATION cmake) + +# Configure and build the NuGet package + +set(CPACK_GENERATOR "NuGet") + +set(CPACK_PACKAGE_NAME "Microsoft.Windows.ImplementationLibrary") +set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "") +set(CPACK_PACKAGE_VENDOR "Microsoft") + +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") + +set(CPACK_NUGET_PACKAGE_LICENSEURL "https://github.com/microsoft/wil/blob/master/LICENSE") + +set(CPACK_NUGET_PACKAGE_TITLE "Windows Implementation Library") +set(CPACK_NUGET_PACKAGE_COPYRIGHT "© Microsoft Corporation. All rights reserved.") +set(CPACK_NUGET_PACKAGE_TAGS "windows utility wil native") + +include(CPack) + add_subdirectory(tests) diff --git a/README.md b/README.md index 8d4e538f8..f4251f842 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,24 @@ C:\vcpkg> vcpkg install wil:x64-windows ``` Note that even though WIL is a header-only library, you still need to install the package for all architectures/platforms you wish to use it with. Otherwise, WIL won't be added to the include path for the missing architectures/platforms. Execute `vcpkg help triplet` for a list of available options. +## Consuming WIL via CMake + +WIL exports and installs a CMake target for use in other CMake projects. You can link your target to WIL with the following: + +```cmake +find_package(WIL) + +add_library(MyCMakeTarget PUBLIC WIL) +``` + +If CMake is unable to locate WIL automatically, you can configure `WIL_DIR` to ensure it is found: + +```cmd +C:\my\project> cmake -DWIL_DIR=%YOUR_WIL_INSTALL_DIRECTORY%/cmake +``` + +These instructions can be combined with the package manager instructions above to consume a stable version of WIL from a CMake project. + # Building/Testing To get started testing WIL, first make sure that you have a recent version of [Visual Studio](https://visualstudio.microsoft.com/downloads/) and the most recent [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk) installed. If you are doing any non-trivial work, also be sure to have a recent version of [Clang](http://releases.llvm.org/download.html) installed. Once everything is installed, open a VS diff --git a/cmake/WILConfig.cmake.in b/cmake/WILConfig.cmake.in new file mode 100644 index 000000000..b871d90ce --- /dev/null +++ b/cmake/WILConfig.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/WILTargets.cmake") diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt deleted file mode 100644 index 1f5688476..000000000 --- a/packaging/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ - -add_subdirectory(nuget) diff --git a/packaging/nuget/CMakeLists.txt b/packaging/nuget/CMakeLists.txt deleted file mode 100644 index f3fd938b2..000000000 --- a/packaging/nuget/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ - -file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/build_tools/nuget.exe" nuget_exe) -file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" nupkg_dir) -file(TO_NATIVE_PATH "${nupkg_dir}/Microsoft.Windows.ImplementationLibrary.${WIL_BUILD_VERSION}.nupkg" wil_nupkg) - -# The build servers don't have an up-to-date version of nuget, so pull it down ourselves... -file(DOWNLOAD https://dist.nuget.org/win-x86-commandline/latest/nuget.exe ${nuget_exe}) - -file(GLOB_RECURSE wil_headers ${CMAKE_SOURCE_DIR}/include/*.h) - -add_custom_command(OUTPUT ${wil_nupkg} - COMMAND ${nuget_exe} pack ${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Windows.ImplementationLibrary.nuspec -OutputDirectory ${nupkg_dir} -Version ${WIL_BUILD_VERSION} -NonInteractive - DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Windows.ImplementationLibrary.nuspec - ${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Windows.ImplementationLibrary.targets - ${wil_headers} - ${CMAKE_SOURCE_DIR}/LICENSE - ${CMAKE_SOURCE_DIR}/ThirdPartyNotices.txt) - -add_custom_target(make_wil_nupkg DEPENDS ${wil_nupkg}) diff --git a/packaging/nuget/Microsoft.Windows.ImplementationLibrary.nuspec b/packaging/nuget/Microsoft.Windows.ImplementationLibrary.nuspec deleted file mode 100644 index be709b9ca..000000000 --- a/packaging/nuget/Microsoft.Windows.ImplementationLibrary.nuspec +++ /dev/null @@ -1,21 +0,0 @@ - - - - Microsoft.Windows.ImplementationLibrary - 0.0.0 - Windows Implementation Library - Microsoft - false - The Windows Implementation Libraries (wil) were created to improve productivity and solve problems commonly seen by Windows developers. - windows utility wil native - © Microsoft Corporation. All rights reserved. - LICENSE - https://github.com/Microsoft/wil - - - - - - - - \ No newline at end of file diff --git a/packaging/nuget/Microsoft.Windows.ImplementationLibrary.targets b/packaging/nuget/Microsoft.Windows.ImplementationLibrary.targets deleted file mode 100644 index 29d756a9f..000000000 --- a/packaging/nuget/Microsoft.Windows.ImplementationLibrary.targets +++ /dev/null @@ -1,8 +0,0 @@ - - - - - $(MSBuildThisFileDirectory)..\..\include\;%(AdditionalIncludeDirectories) - - - diff --git a/scripts/init.cmd b/scripts/init.cmd index cc8efbfbe..921119467 100644 --- a/scripts/init.cmd +++ b/scripts/init.cmd @@ -171,7 +171,7 @@ goto :init set CMAKE_ARGS=%CMAKE_ARGS% -DCMAKE_LINKER=lld-link ) - if "%VERSION%" NEQ "" set CMAKE_ARGS=%CMAKE_ARGS% -DWIL_BUILD_VERSION=%VERSION% + if "%VERSION%" NEQ "" set CMAKE_ARGS=%CMAKE_ARGS% -DCPACK_PACKAGE_VERSION=%VERSION% if %FAST_BUILD%==1 set CMAKE_ARGS=%CMAKE_ARGS% -DFAST_BUILD=ON diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bd4e4f55a..69702ee12 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,6 @@ include(${CMAKE_SOURCE_DIR}/cmake/common_build_flags.cmake) -# All projects need to reference the WIL headers -include_directories(${CMAKE_SOURCE_DIR}/include) - # TODO: Might be worth trying to conditionally do this on SDK version, assuming there's a semi-easy way to detect that include_directories(BEFORE SYSTEM ./workarounds/wrl) diff --git a/tests/app/CMakeLists.txt b/tests/app/CMakeLists.txt index 1118f2353..f57bddc1c 100644 --- a/tests/app/CMakeLists.txt +++ b/tests/app/CMakeLists.txt @@ -19,3 +19,5 @@ target_sources(witest.app PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../WistdTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../wiTest.cpp ) + +target_link_libraries(witest.app PUBLIC WIL) diff --git a/tests/cpplatest/CMakeLists.txt b/tests/cpplatest/CMakeLists.txt index 7ac24aeb3..a47531f04 100644 --- a/tests/cpplatest/CMakeLists.txt +++ b/tests/cpplatest/CMakeLists.txt @@ -35,3 +35,5 @@ target_sources(witest.cpplatest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../WistdTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../wiTest.cpp ) + +target_link_libraries(witest.cpplatest PUBLIC WIL) diff --git a/tests/noexcept/CMakeLists.txt b/tests/noexcept/CMakeLists.txt index 76feacdd9..5c3e9b22f 100644 --- a/tests/noexcept/CMakeLists.txt +++ b/tests/noexcept/CMakeLists.txt @@ -25,3 +25,5 @@ target_sources(witest.noexcept PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../WinRTTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../WistdTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../wiTest.cpp) + +target_link_libraries(witest.noexcept PUBLIC WIL) diff --git a/tests/normal/CMakeLists.txt b/tests/normal/CMakeLists.txt index b146e8e4a..e1aba8344 100644 --- a/tests/normal/CMakeLists.txt +++ b/tests/normal/CMakeLists.txt @@ -19,3 +19,5 @@ target_sources(witest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../WistdTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../wiTest.cpp ) + +target_link_libraries(witest PUBLIC WIL) diff --git a/tests/win7/CMakeLists.txt b/tests/win7/CMakeLists.txt index 8eebc498b..7bd0ec57a 100644 --- a/tests/win7/CMakeLists.txt +++ b/tests/win7/CMakeLists.txt @@ -19,3 +19,5 @@ target_sources(witest.win7 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../WistdTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../wiTest.cpp ) + +target_link_libraries(witest.win7 PUBLIC WIL)