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) # Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: GPL-3.0-or-later # 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) 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) set(RADLER_VERSION 0.0.0)
project(radler VERSION ${RADLER_VERSION}) project(radler VERSION ${RADLER_VERSION})
if(RADLER_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)") if(RADLER_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
...@@ -27,13 +21,6 @@ if(POLICY CMP0076) ...@@ -27,13 +21,6 @@ if(POLICY CMP0076)
cmake_policy(SET CMP0076 NEW) cmake_policy(SET CMP0076 NEW)
endif() 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 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
...@@ -47,24 +34,20 @@ if(PORTABLE) ...@@ -47,24 +34,20 @@ if(PORTABLE)
endif() endif()
endif() endif()
# Include submodules if(NOT COMPILE_AS_EXTERNAL_PROJECT)
set(ExternalSubmoduleDirectories aocommon pybind11 schaapcommon) # Include submodules
foreach(ExternalSubmodule ${ExternalSubmoduleDirectories}) set(ExternalSubmoduleDirectories aocommon pybind11 schaapcommon)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/${ExternalSubmodule}) foreach(ExternalSubmodule ${ExternalSubmoduleDirectories})
message( if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/${ExternalSubmodule})
FATAL_ERROR message(
"The external submodule '${ExternalSubmodule}' is missing in the external/ subdirectory. " FATAL_ERROR
"This is likely the result of downloading a git tarball without submodules. " "The external submodule '${ExternalSubmodule}' is missing in the external/ subdirectory. "
"This is not supported: git tarballs do not provide the required versioning " "This is likely the result of downloading a git tarball without submodules. "
"information for the submodules. Please perform a git clone of this repository." "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() endif()
endforeach()
set(AOCOMMON_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/external/aocommon/include/)
if(RADLER_MASTER_PROJECT)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# Find and include git submodules # Find and include git submodules
find_package(Git QUIET) find_package(Git QUIET)
...@@ -86,41 +69,74 @@ if(RADLER_MASTER_PROJECT) ...@@ -86,41 +69,74 @@ if(RADLER_MASTER_PROJECT)
endif() endif()
endif() endif()
endif() endif()
endif()
# Boost date_time is needed in aocommon if(COMPILE_AS_EXTERNAL_PROJECT)
find_package( message(
Boost STATUS "Radler is compiled as an external project within another project.")
COMPONENTS date_time if(NOT DEFINED AOCOMMON_INCLUDE_DIR)
REQUIRED) 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 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
find_package(Threads REQUIRED)
# Find and include HDF5 # Boost date_time is needed in aocommon
find_package( find_package(
HDF5 Boost
COMPONENTS C CXX COMPONENTS date_time
REQUIRED) REQUIRED)
add_definitions(${HDF5_DEFINITIONS} -DH5_USE_110_API)
# Threads
find_package(Threads REQUIRED)
# Casacore # Find and include HDF5
set(CASACORE_MAKE_REQUIRED_EXTERNALS_OPTIONAL TRUE) find_package(
find_package(Casacore REQUIRED COMPONENTS fits casa ms tables measures) HDF5
COMPONENTS C CXX
REQUIRED)
add_definitions(${HDF5_DEFINITIONS} -DH5_USE_110_API)
# CFitsio # Casacore
find_package(CFITSIO REQUIRED) set(CASACORE_MAKE_REQUIRED_EXTERNALS_OPTIONAL TRUE)
find_package(Casacore REQUIRED COMPONENTS fits casa ms tables measures)
# Python3 and pybind11 # CFitsio
find_package(PythonLibs 3 REQUIRED) find_package(CFITSIO REQUIRED)
find_package(PythonInterp REQUIRED)
message(STATUS "Using python version ${PYTHON_VERSION_STRING}")
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 if(COMPILE_AS_EXTERNAL_PROJECT)
add_subdirectory("${CMAKE_SOURCE_DIR}/external/schaapcommon") add_subdirectory(${SCHAAPCOMMON_SOURCE_DIR}
target_include_directories(schaapcommon SYSTEM PUBLIC ${AOCOMMON_INCLUDE_DIR}) ${PROJECT_BINARY_DIR}/schaapcommon)
endif(RADLER_MASTER_PROJECT) 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 set(RADLER_TARGET_INCLUDE_DIRS
${AOCOMMON_INCLUDE_DIR} ${AOCOMMON_INCLUDE_DIR}
...@@ -129,7 +145,7 @@ set(RADLER_TARGET_INCLUDE_DIRS ...@@ -129,7 +145,7 @@ set(RADLER_TARGET_INCLUDE_DIRS
${CFITSIO_INCLUDE_DIR} ${CFITSIO_INCLUDE_DIR}
${HDF5_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS}
${pybind11_INCLUDE_DIRS} ${pybind11_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/external/schaapcommon/include) ${SCHAAPCOMMON_SOURCE_DIR}/include)
set(RADLER_TARGET_LIBS set(RADLER_TARGET_LIBS
${Boost_DATE_TIME_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${CASACORE_LIBRARIES} ${Boost_DATE_TIME_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${CASACORE_LIBRARIES}
...@@ -139,7 +155,7 @@ set(RADLER_TARGET_LIBS ...@@ -139,7 +155,7 @@ set(RADLER_TARGET_LIBS
add_subdirectory(cpp) add_subdirectory(cpp)
# Compile tests # Compile tests
if(${RADLER_MASTER_PROJECT} AND ${BUILD_TESTING}) if(NOT ${COMPILE_AS_EXTERNAL_PROJECT} AND ${BUILD_TESTING})
include(CTest) include(CTest)
find_package( find_package(
Boost Boost
......
...@@ -5,19 +5,8 @@ ...@@ -5,19 +5,8 @@
function(install_headers_with_directory HEADER_LIST) function(install_headers_with_directory HEADER_LIST)
foreach(HEADER ${HEADER_LIST}) foreach(HEADER ${HEADER_LIST})
string(REGEX MATCH ".*\/" DIR ${HEADER}) string(REGEX MATCH ".*\/" DIR ${HEADER})
if(${RADLER_MASTER_PROJECT}) install(FILES ${HEADER}
# Install public headers to final installation directory. DESTINATION ${CMAKE_INSTALL_PREFIX}/include/radler/${DIR})
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()
endforeach(HEADER) endforeach(HEADER)
endfunction(install_headers_with_directory) endfunction(install_headers_with_directory)
...@@ -93,19 +82,15 @@ if(NOT PORTABLE) ...@@ -93,19 +82,15 @@ if(NOT PORTABLE)
endif() endif()
endif() endif()
if(NOT ${RADLER_MASTER_PROJECT}) if(NOT COMPILE_AS_EXTERNAL_PROJECT)
# Install libradler.so in the radler binary dir of the top level project. include(GNUInstallDirs)
install( install(TARGETS ${PROJECT_NAME}
TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
LIBRARY DESTINATION ${PROJECT_BINARY_DIR}/lib else()
COMPONENT radler-dependency install(TARGETS ${PROJECT_NAME}
EXCLUDE_FROM_ALL) LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif() endif()
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
set(PUBLIC_HEADERS set(PUBLIC_HEADERS
component_list.h component_list.h
radler.h radler.h
...@@ -117,7 +102,7 @@ set(PUBLIC_HEADERS ...@@ -117,7 +102,7 @@ set(PUBLIC_HEADERS
install_headers_with_directory("${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 configure_file(${PROJECT_SOURCE_DIR}/cmake/config/radler-config.cmake.in
${PROJECT_BINARY_DIR}/CMakeFiles/radler-config.cmake @ONLY) ${PROJECT_BINARY_DIR}/CMakeFiles/radler-config.cmake @ONLY)
configure_file( configure_file(
...@@ -128,17 +113,4 @@ if(${RADLER_MASTER_PROJECT}) ...@@ -128,17 +113,4 @@ if(${RADLER_MASTER_PROJECT})
install(FILES ${PROJECT_BINARY_DIR}/CMakeFiles/radler-config.cmake install(FILES ${PROJECT_BINARY_DIR}/CMakeFiles/radler-config.cmake
${PROJECT_BINARY_DIR}/CMakeFiles/radler-config-version.cmake ${PROJECT_BINARY_DIR}/CMakeFiles/radler-config-version.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/radler) 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() 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