diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2018-05-07 20:47:28 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-05-11 13:28:44 (GMT) |
commit | f739752ad6f2d661148faa3691189db9251d34b6 (patch) | |
tree | 6e36e2c344db3c659874ea06bd5a3bfdc8c5a104 /Tests/CMakeLists.txt | |
parent | dd43e6fe895ab84206cab126699e7db7007cc688 (diff) | |
download | CMake-f739752ad6f2d661148faa3691189db9251d34b6.zip CMake-f739752ad6f2d661148faa3691189db9251d34b6.tar.gz CMake-f739752ad6f2d661148faa3691189db9251d34b6.tar.bz2 |
CPack: Add NuGet support
Create a CPack generator that uses `nuget.exe` to create packages:
https://docs.microsoft.com/en-us/nuget/what-is-nuget
NuGet packages could be easily produced from a `*.nuspec` file (running
`nuget pack` in the directory w/ the spec file). The spec filename does
not affect the result `*.nupkg` name -- only `id` and `version` elements
of the spec are used (by NuGet).
Some implementation details:
* Minimize C++ code -- use CMake script do to the job. It just let the
base class (`cmCPackGenerator`) to preinstall everything to a temp
directory, render the spec file and run `nuget pack` in it, harvesting
`*.nupkg` files...;
* Ignore package name (and use default paths) prepared by the base class
(only `CPACK_TEMPORARY_DIRECTORY` is important) -- final package
filename is a responsibility of NuGet, so after generation just scan the
temp directory for the result `*.nupkg` file(s) and update
`packageFileNames` data-member of the generator;
* The generator supports _all-in-one_ (default), _one-group-per-package_
and _one-component-per-package_ modes.
Diffstat (limited to 'Tests/CMakeLists.txt')
-rw-r--r-- | Tests/CMakeLists.txt | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 6e3c3c4..fe8f2cc 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -154,6 +154,15 @@ if(BUILD_TESTING) set(CPACK_BINARY_DEB OFF) endif() + # Look for NuGet to use for tests. + find_program(NUGET_EXECUTABLE NAMES NuGet nuget) + + if(NUGET_EXECUTABLE) + set(CPACK_BINARY_NUGET ON) + else() + set(CPACK_BINARY_NUGET OFF) + endif() + #--------------------------------------------------------------------------- # Add tests below here. @@ -1032,6 +1041,12 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release if(CPACK_BINARY_DEB) list(APPEND ACTIVE_CPACK_GENERATORS DEB) endif() + # Check whether if NuGet command is found + # before adding NuGet tests + if(CPACK_BINARY_NUGET) + list(APPEND ACTIVE_CPACK_GENERATORS NUGET) + set(CPACK_GENERATOR_STRING_NUGET NuGet) + endif() # ACTIVE_CPACK_GENERATORS variable # now contains the list of 'active generators' @@ -1051,7 +1066,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release list(APPEND CWAYLST "IgnoreGroup") list(APPEND CWAYLST "AllInOne") foreach(CPackGen IN LISTS ACTIVE_CPACK_GENERATORS) - set(CPackRun_CPackGen "-DCPackGen=${CPackGen}") + if(NOT DEFINED CPACK_GENERATOR_STRING_${CPackGen}) + set(CPACK_GENERATOR_STRING_${CPackGen} ${CPackGen}) + endif() + set(CPackRun_CPackGen "-DCPackGen=${CPACK_GENERATOR_STRING_${CPackGen}}") foreach(CPackComponentWay ${CWAYLST}) set(CPackRun_CPackComponentWay "-DCPackComponentWay=${CPackComponentWay}") add_test(CPackComponentsForAll-${CPackGen}-${CPackComponentWay} @@ -1062,7 +1080,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release ${build_generator_args} --build-project CPackComponentsForAll --build-options ${build_options} - -DCPACK_GENERATOR:STRING=${CPackGen} + -DCPACK_GENERATOR:STRING=${CPACK_GENERATOR_STRING_${CPackGen}} -DCPACK_BINARY_${CPackGen}:BOOL=ON ${CPackRun_CPackComponentWay} ${CPackComponentsForAll_BUILD_OPTIONS} |