From fa12ab2858b81bbc50d457c7a9f952646801cdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Thu, 28 Apr 2022 16:35:29 +0200 Subject: [PATCH] Support external builds of python bindings, gui, ctbgui and moench stuff (#440) Use already installed version of the slsDetectorPackage. Assumes that the library has already been built and installed either on a system wide location or pointed to by CMAKE_PREFIX_PATH --- CMakeLists.txt | 158 ++++++++++-------- conda-recepie/copy_lib.sh | 2 +- .../moenchExecutables/CMakeLists.txt | 3 +- slsDetectorSoftware/CMakeLists.txt | 2 + slsReceiverSoftware/CMakeLists.txt | 2 + slsSupportLib/CMakeLists.txt | 9 +- 6 files changed, 98 insertions(+), 78 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 291b19164..b691f1ca2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,13 +8,8 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") cmake_policy(SET CMP0074 NEW) include(cmake/project_version.cmake) - -#functions to add compiler flags include(cmake/SlsAddFlag.cmake) - include(cmake/SlsFindZeroMQ.cmake) - -# Include additional modules that are used unconditionally include(GNUInstallDirs) # If conda build, always set lib dir to 'lib' @@ -28,7 +23,7 @@ string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER) # Set targets export name (used by slsDetectorPackage and dependencies) set(TARGETS_EXPORT_NAME "${PROJECT_NAME_LOWER}-targets") -#set(namespace "${PROJECT_NAME}::") +set(namespace "sls::") set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) @@ -39,6 +34,8 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(SLS_MASTER_PROJECT ON) endif() + + option(SLS_USE_HDF5 "HDF5 File format" OFF) option(SLS_BUILD_SHARED_LIBRARIES "Build shared libaries" ON) option(SLS_USE_TEXTCLIENT "Text Client" ON) @@ -71,6 +68,20 @@ if(SLS_BUILD_ONLY_MOENCH) endif() +option(SLS_EXT_BUILD "external build of part of the project" OFF) +if(SLS_EXT_BUILD) + message(STATUS "External build using already installed libraries") + set(SLS_BUILD_SHARED_LIBRARIES OFF CACHE BOOL "Should already exist" FORCE) + set(SLS_USE_TEXTCLIENT OFF CACHE BOOL "Should already exist" FORCE) + set(SLS_USE_DETECTOR OFF CACHE BOOL "Should already exist" FORCE) + set(SLS_USE_RECEIVER OFF CACHE BOOL "Should already exist" FORCE) + set(SLS_USE_RECEIVER_BINARIES OFF CACHE BOOL "Should already exist" FORCE) + set(SLS_MASTER_PROJECT OFF CACHE BOOL "No master proj in case of extbuild" FORCE) +endif() + +#Maybe have an option guarding this? +set(SLS_INTERNAL_RAPIDJSON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/rapidjson) + set(ClangFormat_EXCLUDE_PATTERNS "build/" "libs/" "slsDetectorCalibration/" @@ -81,9 +92,6 @@ set(ClangFormat_EXCLUDE_PATTERNS "build/" ${CMAKE_BINARY_DIR}) find_package(ClangFormat) - - - set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) @@ -102,62 +110,68 @@ else() endif() -#Add two fake libraries to manage options -add_library(slsProjectOptions INTERFACE) -add_library(slsProjectWarnings INTERFACE) -target_compile_features(slsProjectOptions INTERFACE cxx_std_11) -target_compile_options(slsProjectWarnings INTERFACE - -Wall - -Wextra - -Wno-unused-parameter - # -Wold-style-cast - -Wnon-virtual-dtor - -Woverloaded-virtual - -Wdouble-promotion - -Wformat=2 - -Wredundant-decls - # -Wconversion - -Wvla - -Wdouble-promotion - -Werror=return-type - ) - -#Settings for C code -add_library(slsProjectCSettings INTERFACE) -target_compile_options(slsProjectCSettings INTERFACE - -std=gnu99 #fixed - -Wall - -Wextra - -Wno-unused-parameter - -Wdouble-promotion - -Wformat=2 - -Wredundant-decls - -Wdouble-promotion - -Werror=return-type - ) - - -#Testing for minimum version for compilers -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2) - message(FATAL_ERROR "Clang version must be at least 3.2!") - endif() -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) - message(FATAL_ERROR "GCC version must be at least 4.8!") - endif() - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5) - target_compile_options(slsProjectWarnings INTERFACE - -Wno-missing-field-initializers) - endif() +if(SLS_EXT_BUILD) + # Find ourself in case of external build + find_package(slsDetectorPackage ${PROJECT_VERSION} REQUIRED) endif() -# Add or disable warnings depending on if the compiler supports them -# The function checks internally and sets HAS_warning-name -sls_enable_cxx_warning("-Wnull-dereference") -sls_enable_cxx_warning("-Wduplicated-cond") -sls_disable_cxx_warning("-Wclass-memaccess") -sls_disable_c_warning("-Wstringop-truncation") + + +# slsProjectOptions and slsProjectWarnings are used +# to control options for the libraries +if(NOT TARGET slsProjectOptions) + add_library(slsProjectOptions INTERFACE) + target_compile_features(slsProjectOptions INTERFACE cxx_std_11) +endif() + +if (NOT TARGET slsProjectWarnings) + add_library(slsProjectWarnings INTERFACE) + target_compile_options(slsProjectWarnings INTERFACE + -Wall + -Wextra + -Wno-unused-parameter + # -Wold-style-cast + -Wnon-virtual-dtor + -Woverloaded-virtual + -Wdouble-promotion + -Wformat=2 + -Wredundant-decls + # -Wconversion + -Wvla + -Wdouble-promotion + -Werror=return-type + ) + # Add or disable warnings depending on if the compiler supports them + # The function checks internally and sets HAS_warning-name + sls_enable_cxx_warning("-Wnull-dereference") + sls_enable_cxx_warning("-Wduplicated-cond") + sls_disable_cxx_warning("-Wclass-memaccess") + + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5 AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + target_compile_options(slsProjectWarnings INTERFACE + -Wno-missing-field-initializers) +endif() + + +endif() + + +if (NOT TARGET slsProjectCSettings) + #Settings for C code + add_library(slsProjectCSettings INTERFACE) + target_compile_options(slsProjectCSettings INTERFACE + -std=gnu99 #fixed + -Wall + -Wextra + -Wno-unused-parameter + -Wdouble-promotion + -Wformat=2 + -Wredundant-decls + -Wdouble-promotion + -Werror=return-type + ) + sls_disable_c_warning("-Wstringop-truncation") +endif() if(SLS_USE_SANITIZER) @@ -172,19 +186,14 @@ if(SLS_TUNE_LOCAL) endif() -#rapidjson -add_library(rapidjson INTERFACE) -target_include_directories(rapidjson INTERFACE - $ -) - -# Install fake the libraries -install(TARGETS slsProjectOptions slsProjectWarnings rapidjson +if(SLS_MASTER_PROJECT) +install(TARGETS slsProjectOptions slsProjectWarnings EXPORT "${TARGETS_EXPORT_NAME}" LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_INSTALL_RPATH $ORIGIN) @@ -200,8 +209,9 @@ if (SLS_USE_TESTS) endif(SLS_USE_TESTS) -# Common functionallity to detector and receiver -add_subdirectory(slsSupportLib) +if(NOT SLS_EXT_BUILD) + add_subdirectory(slsSupportLib) +endif() if (SLS_USE_DETECTOR OR SLS_USE_TEXTCLIENT) add_subdirectory(slsDetectorSoftware) @@ -225,7 +235,7 @@ endif (SLS_USE_INTEGRATION_TESTS) if (SLS_USE_PYTHON) find_package (Python 3.6 COMPONENTS Interpreter Development) - add_subdirectory(libs/pybind11) + add_subdirectory(libs/pybind11 ${CMAKE_BINARY_DIR}/bin/) add_subdirectory(python) endif(SLS_USE_PYTHON) diff --git a/conda-recepie/copy_lib.sh b/conda-recepie/copy_lib.sh index 71870c916..da40a721a 100755 --- a/conda-recepie/copy_lib.sh +++ b/conda-recepie/copy_lib.sh @@ -19,4 +19,4 @@ cp build/install/bin/slsMultiReceiver $PREFIX/bin/. cp build/install/include/sls/* $PREFIX/include/sls -cp -r build/install/share/ $PREFIX/share +cp -rv build/install/share $PREFIX diff --git a/slsDetectorCalibration/moenchExecutables/CMakeLists.txt b/slsDetectorCalibration/moenchExecutables/CMakeLists.txt index a961da0ea..f6327bad1 100644 --- a/slsDetectorCalibration/moenchExecutables/CMakeLists.txt +++ b/slsDetectorCalibration/moenchExecutables/CMakeLists.txt @@ -56,7 +56,8 @@ foreach(exe ${MOENCH_EXECUTABLES}) ../dataStructures ../interpolations ../../slsReceiverSoftware/include/ - ../../slsSupportLib/include/ + ../../slsSupportLib/include/ + ${SLS_INTERNAL_RAPIDJSON_DIR} ) target_link_libraries(${exe} diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt index 33bfc8432..692302d11 100755 --- a/slsDetectorSoftware/CMakeLists.txt +++ b/slsDetectorSoftware/CMakeLists.txt @@ -17,6 +17,8 @@ add_library(slsDetectorObject OBJECT target_include_directories(slsDetectorObject PUBLIC "$" "$" + PRIVATE + ${SLS_INTERNAL_RAPIDJSON_DIR} ) target_link_libraries(slsDetectorObject diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index a72da71b7..6592f7af9 100755 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -40,6 +40,8 @@ add_library(slsReceiverObject OBJECT target_include_directories(slsReceiverObject PUBLIC "$" "$" + PRIVATE + ${SLS_INTERNAL_RAPIDJSON_DIR} ) target_link_libraries(slsReceiverObject diff --git a/slsSupportLib/CMakeLists.txt b/slsSupportLib/CMakeLists.txt index efa8010fc..1d43aa386 100755 --- a/slsSupportLib/CMakeLists.txt +++ b/slsSupportLib/CMakeLists.txt @@ -34,6 +34,8 @@ set(PUBLICHEADERS if(SLS_DEVEL_HEADERS) set(PUBLICHEADERS ${PUBLICHEADERS} + include/sls/ansi.h + include/sls/logger.h include/sls/file_utils.h include/sls/sls_detector_funcs.h include/sls/ClientSocket.h @@ -46,7 +48,7 @@ if(SLS_DEVEL_HEADERS) include/sls/versionAPI.h include/sls/ZmqSocket.h include/sls/bit_utils.h - include/sls/mdf5.h + include/sls/md5.h include/sls/md5_helper.h ) endif() @@ -75,13 +77,16 @@ target_include_directories(slsSupportObject PUBLIC "$" "$" + PRIVATE + ${SLS_INTERNAL_RAPIDJSON_DIR} ) +message(STATUS "RAPID: ${SLS_INTERNAL_RAPIDJSON_DIR}") + target_link_libraries(slsSupportObject PUBLIC slsProjectOptions libzmq - rapidjson PRIVATE slsProjectWarnings md5sls