Skip to content

Commit

Permalink
Add CMakeLists.txt and modernize CMake
Browse files Browse the repository at this point in the history
- CMakeLists.txt can be included in Projects via add_subdirectory
 and find_package
- add mechanism to extract version number from header file (copied
 from alpaka - thanks to Jan stephan)
- add cuplaConfig.cmake and cuplaTargets.cmake
- add CMake integration tests
  - build external project, which uses cupla via
    - add_subdirectory() and internal alpaka
    - add_subdirectory() and external alpaka
    - find_package()
- add cmake option to build examples
  • Loading branch information
SimeonEhrig committed Aug 2, 2021
1 parent a8d2afd commit 8fb9461
Show file tree
Hide file tree
Showing 23 changed files with 636 additions and 639 deletions.
81 changes: 71 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ include:
- local: '/script/compiler_base.yml'

cuda92:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-gcc:1.1
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-gcc:1.4
variables:
CUPLA_CXX: "g++-6"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda

cuda100:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-gcc:1.1
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-gcc:1.4
variables:
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda

cuda101:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-gcc:1.1
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-gcc:1.4
variables:
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda

cuda102:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda102-gcc:1.1
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda102-gcc:1.4
variables:
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda
Expand Down Expand Up @@ -58,29 +58,90 @@ clang:
extends: .base_clang

cudaClang92:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-clang:1.1
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-clang:1.4
variables:
CUPLA_CXX: "clang++-8 clang++-10 clang++-11"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda_clang

cudaClang100:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-clang:1.1
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-clang:1.4
variables:
CUPLA_CXX: "clang++-8 clang++-9 clang++-10 clang++-11"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda_clang

cudaClang101:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-clang:1.1
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-clang:1.4
variables:
CUPLA_CXX: "clang++-9 clang++-10 clang++-11"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda_clang

hip38:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-rocm3.8:1.1
hip42:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-rocm4.2:1.4
variables:
CMAKE_MODULE_PATH: "/opt/rocm-3.8.0/hip/cmake"
CMAKE_MODULE_PATH: "/opt/rocm-4.2.0/hip/cmake"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_hip

################################################################################
# CMake integration test
#

# build external project and use cupla via cmake add_subdirectory()
# use internal alpaka
addSubdirectoryInternal:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4
variables:
GIT_SUBMODULE_STRATEGY: normal
CUPLA_BOOST_VERSION: 1.73.0
CUPLA_ALPAKA_PROVIDER: "internal"
script:
- source script/integration/build_add_subdirectory.sh
tags:
- x86_64

# build external project and use cupla via cmake add_subdirectory()
# use installed alpaka
addSubdirectoryExternal:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4
variables:
GIT_SUBMODULE_STRATEGY: normal
CUPLA_BOOST_VERSION: 1.73.0
CUPLA_ALPAKA_PROVIDER: "external"
script:
- source script/integration/install_alpaka.sh
- source script/integration/build_add_subdirectory.sh
tags:
- x86_64

# build external project and use cupla via cmake find_package()
# cupla was installed with disabled examples
findPackageWithoutExample:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4
variables:
GIT_SUBMODULE_STRATEGY: normal
CUPLA_BOOST_VERSION: 1.73.0
CUPLA_BUILD_EXAMPLE: "OFF"
script:
- source script/integration/install_alpaka.sh
- source script/integration/install_cupla.sh
- source script/integration/build_find_package.sh
tags:
- x86_64

# build external project and use cupla via cmake find_package()
# cupla was installed with enabled examples
findPackageWithExample:
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4
variables:
GIT_SUBMODULE_STRATEGY: normal
CUPLA_BOOST_VERSION: 1.73.0
CUPLA_BUILD_EXAMPLE: "ON"
script:
- source script/integration/install_alpaka.sh
- source script/integration/install_cupla.sh
- source script/integration/build_find_package.sh
tags:
- x86_64
149 changes: 149 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#
# Copyright 2016-2021 Rene Widera, Benjamin Worpitz, Simeon Ehrig
#
# This file is part of cupla.
#
# cupla is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cupla is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with cupla.
# If not, see <http://www.gnu.org/licenses/>.
#

################################################################################
# Required cmake version.
################################################################################

cmake_minimum_required(VERSION 3.18.0)

################################################################################
# Setup project information
################################################################################

# Find cupla version.
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/cupla/version.hpp" CUPLA_VERSION_MAJOR_HPP REGEX "#define CUPLA_VERSION_MAJOR ")
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/cupla/version.hpp" CUPLA_VERSION_MINOR_HPP REGEX "#define CUPLA_VERSION_MINOR ")
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/cupla/version.hpp" CUPLA_VERSION_PATCH_HPP REGEX "#define CUPLA_VERSION_PATCH ")

string(REGEX MATCH "([0-9]+)" CUPLA_VERSION_MAJOR ${CUPLA_VERSION_MAJOR_HPP})
string(REGEX MATCH "([0-9]+)" CUPLA_VERSION_MINOR ${CUPLA_VERSION_MINOR_HPP})
string(REGEX MATCH "([0-9]+)" CUPLA_VERSION_PATCH ${CUPLA_VERSION_PATCH_HPP})

set(PACKAGE_VERSION "${CUPLA_VERSION_MAJOR}.${CUPLA_VERSION_MINOR}.${CUPLA_VERSION_PATCH}")


project(cupla VERSION ${CUPLA_VERSION_MAJOR}.${CUPLA_VERSION_MINOR}.${CUPLA_VERSION_PATCH}
DESCRIPTION "cupla is a simple CUDA like user interface for the platform independent parallel kernel acceleration library alpaka."
HOMEPAGE_URL "https://github.com/alpaka-group/cupla"
LANGUAGES CXX)
include(GNUInstallDirs)

################################################################################
# cupla options
################################################################################

option(CUPLA_STREAM_ASYNC_ENABLE "Enable asynchronous streams" ON)
option(cupla_BUILD_EXAMPLES "Build examples" OFF)

################################################################################
# setup alpaka
################################################################################

# the min and max. supported alpaka version is also copied to the cuplaConfig.cmake
set(_CUPLA_MIN_ALPAKA_VERSION 0.7.0)
set(_CUPLA_UNSUPPORTED_ALPAKA_VERSION 0.8.0)

# the alpaka provider for the internal alpaka is only available,
# if cupla is used via add_subdirectory in another project
# or examples are build
if(cupla_BUILD_EXAMPLES OR (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}))
set(cupla_ALPAKA_PROVIDER "internal" CACHE STRING "Select which alpaka is used")
set_property(CACHE cupla_ALPAKA_PROVIDER PROPERTY STRINGS "internal;external")
mark_as_advanced(cupla_ALPAKA_PROVIDER)

if(${cupla_ALPAKA_PROVIDER} STREQUAL "internal")
set(alpaka_BUILD_EXAMPLES OFF)
set(BUILD_TESTING OFF)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/alpaka)
else()
find_package(alpaka ${_CUPLA_MIN_ALPAKA_VERSION} REQUIRED HINTS $ENV{ALPAKA_ROOT})

if(alpaka_VERSION VERSION_GREATER_EQUAL _CUPLA_UNSUPPORTED_ALPAKA_VERSION)
message(WARNING "Unsupported alpaka version ${alpaka_VERSION}. "
"Supported versions [${_CUPLA_MIN_ALPAKA_VERSION},${_CUPLA_UNSUPPORTED_ALPAKA_VERSION}).")
endif()
endif()

if(NOT TARGET alpaka::alpaka)
message(FATAL_ERROR "Required cupla dependency alpaka could not be found!")
endif()
endif()

################################################################################
# cupla Target.
################################################################################

# create cupla target only if the cupla is used via add_subdirectory
# or examples are build
# for the explanation please have a look in the cuplaConfig.cmake.in
if(cupla_BUILD_EXAMPLES OR (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}))
include("${CMAKE_CURRENT_LIST_DIR}/cmake/addExecutable.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/cuplaTargetHelper.cmake")

createCuplaTarget(${PROJECT_NAME}
${PROJECT_SOURCE_DIR}/include # include directory path
${PROJECT_SOURCE_DIR}/src # src directory path
)
endif()


################################################################################
# add examples
################################################################################

if(cupla_BUILD_EXAMPLES)
add_subdirectory(example/)
endif()

################################################################################
# install cupla
################################################################################

if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
include(CMakePackageConfigHelpers)

set(_CUPLA_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(_CUPLA_SOURCE_CMAKEDIR "${PROJECT_SOURCE_DIR}/cmake/")

write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

configure_package_config_file(
"${_CUPLA_SOURCE_CMAKEDIR}/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${_CUPLA_INSTALL_CMAKEDIR}
PATH_VARS _CUPLA_MIN_ALPAKA_VERSION _CUPLA_UNSUPPORTED_ALPAKA_VERSION)

install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${_CUPLA_INSTALL_CMAKEDIR})

install(FILES "${_CUPLA_SOURCE_CMAKEDIR}/addExecutable.cmake"
"${_CUPLA_SOURCE_CMAKEDIR}/cuplaTargetHelper.cmake"
DESTINATION ${_CUPLA_INSTALL_CMAKEDIR})

install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include)
# copy source files instead compiled library
# this is necessary because some functions use the ACC as a template parameter,
# but the ACC is not defined at the install time of cupla
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION src/cupla)
endif()
Loading

0 comments on commit 8fb9461

Please sign in to comment.