Skip to content
Snippets Groups Projects
Commit 3bda4641 authored by Jakob Maljaars's avatar Jakob Maljaars
Browse files

Merge branch 'prepare-for-externalproject-compilation' into 'ast-779-fill-deconvolution-repo'

Prepare for externalproject compilation

See merge request !4
parents f04cd35a 1431e9aa
No related branches found
No related tags found
2 merge requests!4Prepare for externalproject compilation,!1AST-779 set up deconvolution repository
Pipeline #28317 passed
# Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Radler's cmake configuration supports two different approaches for compiling
# Radler:
#
# 1. Compiling and linking against Radler as stand-alone library (default).
# 2. Compiling and linking against Radler as a submodule "on the fly". This can
# be done by making targets in the dependent package dependent on the
# install-radler target from this repo. In this approach it is assumed that
# the depending package provides the ALL the dependencies for Radler. This
# approach is used in WSClean.
cmake_minimum_required(VERSION 3.8)
# When Radler is compiled as an ExternalProject inside another project, set this
# option to On. See, e.g., the wsclean CMake file for an example.
option(COMPILE_AS_EXTERNAL_PROJECT OFF)
set(RADLER_VERSION 0.0.0)
project(radler VERSION ${RADLER_VERSION})
if(RADLER_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
......@@ -27,13 +21,6 @@ if(POLICY CMP0076)
cmake_policy(SET CMP0076 NEW)
endif()
# Convenience conditional to distinguish between stand-alone vs dependency
# builds
set(RADLER_MASTER_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(RADLER_MASTER_PROJECT ON)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
......@@ -47,24 +34,20 @@ if(PORTABLE)
endif()
endif()
# Include submodules
set(ExternalSubmoduleDirectories aocommon pybind11 schaapcommon)
foreach(ExternalSubmodule ${ExternalSubmoduleDirectories})
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/${ExternalSubmodule})
message(
FATAL_ERROR
"The external submodule '${ExternalSubmodule}' is missing in the external/ subdirectory. "
"This is likely the result of downloading a git tarball without submodules. "
"This is not supported: git tarballs do not provide the required versioning "
"information for the submodules. Please perform a git clone of this repository."
)
endif()
endforeach()
set(AOCOMMON_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/external/aocommon/include/)
if(RADLER_MASTER_PROJECT)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
if(NOT COMPILE_AS_EXTERNAL_PROJECT)
# Include submodules
set(ExternalSubmoduleDirectories aocommon pybind11 schaapcommon)
foreach(ExternalSubmodule ${ExternalSubmoduleDirectories})
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/${ExternalSubmodule})
message(
FATAL_ERROR
"The external submodule '${ExternalSubmodule}' is missing in the external/ subdirectory. "
"This is likely the result of downloading a git tarball without submodules. "
"This is not supported: git tarballs do not provide the required versioning "
"information for the submodules. Please perform a git clone of this repository."
)
endif()
endforeach()
# Find and include git submodules
find_package(Git QUIET)
......@@ -86,41 +69,74 @@ if(RADLER_MASTER_PROJECT)
endif()
endif()
endif()
endif()
# Boost date_time is needed in aocommon
find_package(
Boost
COMPONENTS date_time
REQUIRED)
if(COMPILE_AS_EXTERNAL_PROJECT)
message(
STATUS "Radler is compiled as an external project within another project.")
if(NOT DEFINED AOCOMMON_INCLUDE_DIR)
message(
FATAL_ERROR
"AOCOMMON_INCLUDE_DIR not specified. Please add -DAOCOMMON_INCLUDE_DIR to the CMAKE_ARGS."
)
endif()
if(NOT DEFINED SCHAAPCOMMON_SOURCE_DIR)
message(
FATAL_ERROR
"SCHAAPCOMMON_SOURCE_DIR not specified. Please add -DSCHAAPCOMMON_SOURCE_DIR to the CMAKE_ARGS."
)
endif()
if(NOT DEFINED PYBIND11_SOURCE_DIR)
message(
FATAL_ERROR
"PYBIND11_SOURCE_DIR not specified. Please add -DPYBIND11_SOURCE_DIR to the CMAKE_ARGS."
)
endif()
else()
set(AOCOMMON_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/external/aocommon/include)
set(SCHAAPCOMMON_SOURCE_DIR ${CMAKE_SOURCE_DIR}/external/schaapcommon)
set(PYBIND11_SOURCE_DIR ${CMAKE_SOURCE_DIR}/external/pybind11)
endif()
# Threads
find_package(Threads REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# Find and include HDF5
find_package(
HDF5
COMPONENTS C CXX
REQUIRED)
add_definitions(${HDF5_DEFINITIONS} -DH5_USE_110_API)
# Boost date_time is needed in aocommon
find_package(
Boost
COMPONENTS date_time
REQUIRED)
# Threads
find_package(Threads REQUIRED)
# Casacore
set(CASACORE_MAKE_REQUIRED_EXTERNALS_OPTIONAL TRUE)
find_package(Casacore REQUIRED COMPONENTS fits casa ms tables measures)
# Find and include HDF5
find_package(
HDF5
COMPONENTS C CXX
REQUIRED)
add_definitions(${HDF5_DEFINITIONS} -DH5_USE_110_API)
# CFitsio
find_package(CFITSIO REQUIRED)
# Casacore
set(CASACORE_MAKE_REQUIRED_EXTERNALS_OPTIONAL TRUE)
find_package(Casacore REQUIRED COMPONENTS fits casa ms tables measures)
# Python3 and pybind11
find_package(PythonLibs 3 REQUIRED)
find_package(PythonInterp REQUIRED)
message(STATUS "Using python version ${PYTHON_VERSION_STRING}")
# CFitsio
find_package(CFITSIO REQUIRED)
add_subdirectory("${CMAKE_SOURCE_DIR}/external/pybind11")
# Python3
find_package(PythonLibs 3 REQUIRED)
find_package(PythonInterp REQUIRED)
message(STATUS "Using python version ${PYTHON_VERSION_STRING}")
# Schaapcommon, schaapcommon target needs to include aocommon headers
add_subdirectory("${CMAKE_SOURCE_DIR}/external/schaapcommon")
target_include_directories(schaapcommon SYSTEM PUBLIC ${AOCOMMON_INCLUDE_DIR})
endif(RADLER_MASTER_PROJECT)
if(COMPILE_AS_EXTERNAL_PROJECT)
add_subdirectory(${SCHAAPCOMMON_SOURCE_DIR}
${PROJECT_BINARY_DIR}/schaapcommon)
add_subdirectory(${PYBIND11_SOURCE_DIR} ${PROJECT_BINARY_DIR}/pybind11)
else()
add_subdirectory(${SCHAAPCOMMON_SOURCE_DIR})
add_subdirectory(${PYBIND11_SOURCE_DIR})
endif()
target_include_directories(schaapcommon SYSTEM PUBLIC ${AOCOMMON_INCLUDE_DIR})
set(RADLER_TARGET_INCLUDE_DIRS
${AOCOMMON_INCLUDE_DIR}
......@@ -129,7 +145,7 @@ set(RADLER_TARGET_INCLUDE_DIRS
${CFITSIO_INCLUDE_DIR}
${HDF5_INCLUDE_DIRS}
${pybind11_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/external/schaapcommon/include)
${SCHAAPCOMMON_SOURCE_DIR}/include)
set(RADLER_TARGET_LIBS
${Boost_DATE_TIME_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${CASACORE_LIBRARIES}
......@@ -139,7 +155,7 @@ set(RADLER_TARGET_LIBS
add_subdirectory(cpp)
# Compile tests
if(${RADLER_MASTER_PROJECT} AND ${BUILD_TESTING})
if(NOT ${COMPILE_AS_EXTERNAL_PROJECT} AND ${BUILD_TESTING})
include(CTest)
find_package(
Boost
......
......@@ -5,19 +5,8 @@
function(install_headers_with_directory HEADER_LIST)
foreach(HEADER ${HEADER_LIST})
string(REGEX MATCH ".*\/" DIR ${HEADER})
if(${RADLER_MASTER_PROJECT})
# Install public headers to final installation directory.
install(FILES ${HEADER}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/radler/${DIR})
else()
# Public headers are only installed to build directory in case Radler is a
# dependency.
install(
FILES ${HEADER}
DESTINATION ${PROJECT_BINARY_DIR}/include/radler/${DIR}
COMPONENT radler-dependency
EXCLUDE_FROM_ALL)
endif()
install(FILES ${HEADER}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/radler/${DIR})
endforeach(HEADER)
endfunction(install_headers_with_directory)
......@@ -93,19 +82,15 @@ if(NOT PORTABLE)
endif()
endif()
if(NOT ${RADLER_MASTER_PROJECT})
# Install libradler.so in the radler binary dir of the top level project.
install(
TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${PROJECT_BINARY_DIR}/lib
COMPONENT radler-dependency
EXCLUDE_FROM_ALL)
if(NOT COMPILE_AS_EXTERNAL_PROJECT)
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
else()
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif()
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
set(PUBLIC_HEADERS
component_list.h
radler.h
......@@ -117,7 +102,7 @@ set(PUBLIC_HEADERS
install_headers_with_directory("${PUBLIC_HEADERS}")
if(${RADLER_MASTER_PROJECT})
if(NOT COMPILE_AS_EXTERNAL_PROJECT)
configure_file(${PROJECT_SOURCE_DIR}/cmake/config/radler-config.cmake.in
${PROJECT_BINARY_DIR}/CMakeFiles/radler-config.cmake @ONLY)
configure_file(
......@@ -128,17 +113,4 @@ if(${RADLER_MASTER_PROJECT})
install(FILES ${PROJECT_BINARY_DIR}/CMakeFiles/radler-config.cmake
${PROJECT_BINARY_DIR}/CMakeFiles/radler-config-version.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/radler)
else()
configure_file(${PROJECT_SOURCE_DIR}/cmake/config/radler-config.cmake.in
${PROJECT_BINARY_DIR}/share/radler/radler-config.cmake @ONLY)
configure_file(
${PROJECT_SOURCE_DIR}/cmake/config/radler-config-version.cmake.in
${PROJECT_BINARY_DIR}/share/radler/radler-config-version.cmake @ONLY)
# Make a target to install the radler-dependency
add_custom_target(
install-radler
COMMAND cmake -DCOMPONENT=radler-dependency -P
${PROJECT_BINARY_DIR}/cmake_install.cmake
DEPENDS ${PROJECT_NAME})
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment