-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from robertmaynard/fea/add_cmake_write_version
Introduce `rapids_cmake_write_version_file`
- Loading branch information
Showing
11 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. cmake-module:: ../../rapids-cmake/cmake/write_version_file.cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2021, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#define @PROJECT_NAME@_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ | ||
#define @PROJECT_NAME@_VERSION_MINOR @PROJECT_VERSION_MINOR@ | ||
#define @PROJECT_NAME@_VERSION_PATCH @PROJECT_VERSION_PATCH@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#============================================================================= | ||
# Copyright (c) 2018-2021, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#============================================================================= | ||
include_guard(GLOBAL) | ||
|
||
|
||
#[=======================================================================[.rst: | ||
rapids_cmake_write_version_file | ||
------------------------------- | ||
|
||
.. versionadded:: v21.08.00 | ||
|
||
Generate a C++ header file that hold the version (`X.Y.Z`) information of the calling project. | ||
|
||
.. code-block:: cmake | ||
|
||
rapids_cmake_write_version_file(file_path) | ||
|
||
The file generated by :cmake:command:`rapids_cmake_write_version_file` will hold the following | ||
components of a `X.Y.Z` version string as C++ defines, extracted from the | ||
CMake :cmake:command:`project` call. | ||
|
||
- <PROJECT_NAME>_VERSION_MAJOR (X) | ||
- <PROJECT_NAME>_VERSION_MINOR (Y) | ||
- <PROJECT_NAME>_VERSION_PATCH (Z) | ||
|
||
``file_path`` | ||
Either an absolute or relative path. | ||
When a relative path, the absolute location will be computed from | ||
cmake:variable:`CMAKE_CURRENT_BINARY_DIR` | ||
|
||
#]=======================================================================] | ||
function(rapids_cmake_write_version_file file_path) | ||
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cmake.write_version_file") | ||
|
||
cmake_path(IS_RELATIVE file_path is_relative) | ||
if(is_relative) | ||
cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR file_path OUTPUT_VARIABLE output_path) | ||
else() | ||
set(output_path "${file_path}") | ||
endif() | ||
|
||
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/version.hpp.in" "${output_path}" @ONLY) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#============================================================================= | ||
# Copyright (c) 2018-2021, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#============================================================================= | ||
include(${rapids-cmake-dir}/cmake/write_version_file.cmake) | ||
|
||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(DEMO VERSION 2.4 LANGUAGES NONE) | ||
rapids_cmake_write_version_file("${CMAKE_CURRENT_BINARY_DIR}/demo/version.h") | ||
|
||
project(NESTED VERSION 3.14.159 LANGUAGES NONE) | ||
rapids_cmake_write_version_file("${CMAKE_CURRENT_BINARY_DIR}/nested/version.h") | ||
|
||
enable_language(CXX) | ||
add_executable(write_version main.cpp) | ||
target_include_directories(write_version PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2019-2021, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <type_traits> | ||
#include <demo/version.h> | ||
#include <nested/version.h> | ||
|
||
constexpr int dmajor = DEMO_VERSION_MAJOR; | ||
constexpr int dminor = DEMO_VERSION_MINOR; | ||
constexpr int dpatch = DEMO_VERSION_MPATCH; | ||
|
||
constexpr int nmajor = NESTED_VERSION_MAJOR; | ||
constexpr int nminor = NESTED_VERSION_MINOR; | ||
constexpr int npatch = NESTED_VERSION_MPATCH; | ||
|
||
int main() | ||
{ | ||
static_assert(dmajor == 2); | ||
static_assert(dminor == 4); | ||
static_assert(dpatch == 0); | ||
|
||
|
||
static_assert(nmajor == 3); | ||
static_assert(nminor == 14); | ||
static_assert(npatch == 159); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#============================================================================= | ||
# Copyright (c) 2018-2021, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#============================================================================= | ||
include(${rapids-cmake-dir}/cmake/write_version_file.cmake) | ||
|
||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(DEMO VERSION 3.2.1 LANGUAGES NONE) | ||
rapids_cmake_write_version_file(demo_version.hpp) | ||
|
||
project(NESTED VERSION 3.14.159 LANGUAGES NONE) | ||
rapids_cmake_write_version_file(nested_version.hpp) | ||
|
||
enable_language(CXX) | ||
add_executable(write_version main.cpp) | ||
target_include_directories(write_version PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2019-2021, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <type_traits> | ||
#include <demo_version.hpp> | ||
#include <nested_version.hpp> | ||
|
||
constexpr int dmajor = DEMO_VERSION_MAJOR; | ||
constexpr int dminor = DEMO_VERSION_MINOR; | ||
constexpr int dpatch = DEMO_VERSION_MPATCH; | ||
|
||
constexpr int nmajor = NESTED_VERSION_MAJOR; | ||
constexpr int nminor = NESTED_VERSION_MINOR; | ||
constexpr int npatch = NESTED_VERSION_MPATCH; | ||
|
||
int main() | ||
{ | ||
static_assert(dmajor == 3); | ||
static_assert(dminor == 2); | ||
static_assert(dpatch == 1); | ||
|
||
static_assert(nmajor == 3); | ||
static_assert(nminor == 14); | ||
static_assert(npatch == 159); | ||
return 0; | ||
} |