From 75b4d8fef8db7fa21b0a3693feee3a5bcc8a7339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 17 Jun 2020 13:12:26 +0200 Subject: [PATCH] test: Add CMake subproject example and test --- examples/use_cmake_subproject/CMakeLists.txt | 17 +++++++++++ examples/use_cmake_subproject/intx/.gitignore | 3 ++ .../use_cmake_subproject/intx/COPY_INTX_HERE | 0 examples/use_cmake_subproject/use_int128.cpp | 10 +++++++ examples/use_cmake_subproject/use_intx.cpp | 10 +++++++ test/integration/CMakeLists.txt | 3 +- .../cmake_subproject/CMakeLists.txt | 30 +++++++++++++++++++ 7 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 examples/use_cmake_subproject/CMakeLists.txt create mode 100644 examples/use_cmake_subproject/intx/.gitignore create mode 100644 examples/use_cmake_subproject/intx/COPY_INTX_HERE create mode 100644 examples/use_cmake_subproject/use_int128.cpp create mode 100644 examples/use_cmake_subproject/use_intx.cpp create mode 100644 test/integration/cmake_subproject/CMakeLists.txt diff --git a/examples/use_cmake_subproject/CMakeLists.txt b/examples/use_cmake_subproject/CMakeLists.txt new file mode 100644 index 00000000..ef6ccd0f --- /dev/null +++ b/examples/use_cmake_subproject/CMakeLists.txt @@ -0,0 +1,17 @@ +# intx: extended precision integer library. +# Copyright 2019-2020 Pawel Bylica. +# Licensed under the Apache License, Version 2.0. + +# This example shows how to use intx CMake subproject. + +cmake_minimum_required(VERSION 3.10) + +project(use_intx_cmake_subproject LANGUAGES CXX) + +add_subdirectory(intx) + +add_executable(use_int128 use_int128.cpp) +target_link_libraries(use_int128 PRIVATE intx::int128) + +add_executable(use_intx use_intx.cpp) +target_link_libraries(use_intx PRIVATE intx::intx) diff --git a/examples/use_cmake_subproject/intx/.gitignore b/examples/use_cmake_subproject/intx/.gitignore new file mode 100644 index 00000000..84aef393 --- /dev/null +++ b/examples/use_cmake_subproject/intx/.gitignore @@ -0,0 +1,3 @@ +* +!/.gitignore +!/COPY_INTX_HERE diff --git a/examples/use_cmake_subproject/intx/COPY_INTX_HERE b/examples/use_cmake_subproject/intx/COPY_INTX_HERE new file mode 100644 index 00000000..e69de29b diff --git a/examples/use_cmake_subproject/use_int128.cpp b/examples/use_cmake_subproject/use_int128.cpp new file mode 100644 index 00000000..6789e437 --- /dev/null +++ b/examples/use_cmake_subproject/use_int128.cpp @@ -0,0 +1,10 @@ +// intx: extended precision integer library. +// Copyright 2019-2020 Pawel Bylica. +// Licensed under the Apache License, Version 2.0. + +#include + +int main(int argc, char**) +{ + return static_cast(argc / intx::uint128{1, 0}); +} diff --git a/examples/use_cmake_subproject/use_intx.cpp b/examples/use_cmake_subproject/use_intx.cpp new file mode 100644 index 00000000..1b7069b4 --- /dev/null +++ b/examples/use_cmake_subproject/use_intx.cpp @@ -0,0 +1,10 @@ +// intx: extended precision integer library. +// Copyright 2019-2020 Pawel Bylica. +// Licensed under the Apache License, Version 2.0. + +#include + +int main(int argc, char**) +{ + return static_cast(intx::uint512{argc} / (intx::uint512{1} << 111)); +} diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index 2fefc1bd..fcb848bd 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -1,5 +1,6 @@ # intx: extended precision integer library. -# Copyright 2019 Pawel Bylica. +# Copyright 2019-2020 Pawel Bylica. # Licensed under the Apache License, Version 2.0. add_subdirectory(cmake_package) +add_subdirectory(cmake_subproject) diff --git a/test/integration/cmake_subproject/CMakeLists.txt b/test/integration/cmake_subproject/CMakeLists.txt new file mode 100644 index 00000000..abcfcb1c --- /dev/null +++ b/test/integration/cmake_subproject/CMakeLists.txt @@ -0,0 +1,30 @@ +# intx: extended precision integer library. +# Copyright 2020 Pawel Bylica. +# Licensed under the Apache License, Version 2.0. + +# Test suite for using intx as a CMake subproject. + +# All files needed to build intx as a CMake subproject: +file( + COPY + ${PROJECT_SOURCE_DIR}/CMakeLists.txt + ${PROJECT_SOURCE_DIR}/cmake + ${PROJECT_SOURCE_DIR}/include + DESTINATION ${PROJECT_SOURCE_DIR}/examples/use_cmake_subproject/intx +) + +set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/build) +file(MAKE_DIRECTORY ${build_dir}) + +if(CMAKE_BUILD_TYPE) + set(build_type_arg -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}) +endif() + +add_test( + NAME ${PROJECT_NAME}/cmake_subproject/use_cmake_subproject + COMMAND + ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} + ${PROJECT_SOURCE_DIR}/examples/use_cmake_subproject + ${build_type_arg} + WORKING_DIRECTORY ${build_dir} +)