Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add CMake subproject example and test #160

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/use_cmake_subproject/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions examples/use_cmake_subproject/intx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!/.gitignore
!/COPY_INTX_HERE
Empty file.
10 changes: 10 additions & 0 deletions examples/use_cmake_subproject/use_int128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// intx: extended precision integer library.
// Copyright 2019-2020 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include <intx/int128.hpp>

int main(int argc, char**)
{
return static_cast<int>(argc / intx::uint128{1, 0});
}
10 changes: 10 additions & 0 deletions examples/use_cmake_subproject/use_intx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// intx: extended precision integer library.
// Copyright 2019-2020 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include <intx/intx.hpp>

int main(int argc, char**)
{
return static_cast<int>(intx::uint512{argc} / (intx::uint512{1} << 111));
}
3 changes: 2 additions & 1 deletion test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 30 additions & 0 deletions test/integration/cmake_subproject/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)