ext build works

This commit is contained in:
Erik Frojdh 2022-04-28 14:51:15 +02:00
parent 12c5844bc9
commit dff6218b4d
6 changed files with 93 additions and 76 deletions

View File

@ -8,13 +8,8 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
cmake_policy(SET CMP0074 NEW) cmake_policy(SET CMP0074 NEW)
include(cmake/project_version.cmake) include(cmake/project_version.cmake)
#functions to add compiler flags
include(cmake/SlsAddFlag.cmake) include(cmake/SlsAddFlag.cmake)
include(cmake/SlsFindZeroMQ.cmake) include(cmake/SlsFindZeroMQ.cmake)
# Include additional modules that are used unconditionally
include(GNUInstallDirs) include(GNUInstallDirs)
# If conda build, always set lib dir to 'lib' # 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 (used by slsDetectorPackage and dependencies)
set(TARGETS_EXPORT_NAME "${PROJECT_NAME_LOWER}-targets") 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}) 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) set(SLS_MASTER_PROJECT ON)
endif() endif()
option(SLS_USE_HDF5 "HDF5 File format" OFF) option(SLS_USE_HDF5 "HDF5 File format" OFF)
option(SLS_BUILD_SHARED_LIBRARIES "Build shared libaries" ON) option(SLS_BUILD_SHARED_LIBRARIES "Build shared libaries" ON)
option(SLS_USE_TEXTCLIENT "Text Client" ON) option(SLS_USE_TEXTCLIENT "Text Client" ON)
@ -71,6 +68,19 @@ if(SLS_BUILD_ONLY_MOENCH)
endif() 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/" set(ClangFormat_EXCLUDE_PATTERNS "build/"
"libs/" "libs/"
@ -82,9 +92,6 @@ set(ClangFormat_EXCLUDE_PATTERNS "build/"
${CMAKE_BINARY_DIR}) ${CMAKE_BINARY_DIR})
find_package(ClangFormat) find_package(ClangFormat)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
@ -102,43 +109,6 @@ else()
message(STATUS "Building without link time optimization") message(STATUS "Building without link time optimization")
endif() 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 #Testing for minimum version for compilers
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
@ -154,12 +124,62 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
endif() endif()
endif() endif()
if(SLS_EXT_BUILD)
# Find ourself in case of external build
find_package(slsDetectorPackage 6 REQUIRED)
endif()
# 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 # Add or disable warnings depending on if the compiler supports them
# The function checks internally and sets HAS_warning-name # The function checks internally and sets HAS_warning-name
sls_enable_cxx_warning("-Wnull-dereference") sls_enable_cxx_warning("-Wnull-dereference")
sls_enable_cxx_warning("-Wduplicated-cond") sls_enable_cxx_warning("-Wduplicated-cond")
sls_disable_cxx_warning("-Wclass-memaccess") sls_disable_cxx_warning("-Wclass-memaccess")
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") sls_disable_c_warning("-Wstringop-truncation")
endif()
if(SLS_USE_SANITIZER) if(SLS_USE_SANITIZER)
@ -174,19 +194,14 @@ if(SLS_TUNE_LOCAL)
endif() endif()
#rapidjson if(SLS_MASTER_PROJECT)
add_library(rapidjson INTERFACE) install(TARGETS slsProjectOptions slsProjectWarnings
target_include_directories(rapidjson INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libs/rapidjson>
)
# Install fake the libraries
install(TARGETS slsProjectOptions slsProjectWarnings rapidjson
EXPORT "${TARGETS_EXPORT_NAME}" EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
) )
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_INSTALL_RPATH $ORIGIN) set(CMAKE_INSTALL_RPATH $ORIGIN)
@ -202,8 +217,9 @@ if (SLS_USE_TESTS)
endif(SLS_USE_TESTS) endif(SLS_USE_TESTS)
# Common functionallity to detector and receiver if(NOT SLS_EXT_BUILD)
add_subdirectory(slsSupportLib) add_subdirectory(slsSupportLib)
endif()
if (SLS_USE_DETECTOR OR SLS_USE_TEXTCLIENT) if (SLS_USE_DETECTOR OR SLS_USE_TEXTCLIENT)
add_subdirectory(slsDetectorSoftware) add_subdirectory(slsDetectorSoftware)
@ -226,6 +242,8 @@ if (SLS_USE_INTEGRATION_TESTS)
endif (SLS_USE_INTEGRATION_TESTS) endif (SLS_USE_INTEGRATION_TESTS)
if (SLS_USE_PYTHON) if (SLS_USE_PYTHON)
find_package (Python 3.6 COMPONENTS Interpreter Development)
add_subdirectory(libs/pybind11 ${CMAKE_BINARY_DIR}/bin/)
add_subdirectory(python) add_subdirectory(python)
endif(SLS_USE_PYTHON) endif(SLS_USE_PYTHON)

View File

@ -1,17 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-other # SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package # Copyright (C) 2021 Contributors to the SLS Detector Package
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
#if we are only building the python extension
cmake_minimum_required(VERSION 3.12)
project(slsdet)
find_package(slsDetectorPackage 6 REQUIRED)
endif()
find_package (Python 3.6 COMPONENTS Interpreter Development)
add_subdirectory(../libs/pybind11 ${CMAKE_BINARY_DIR}/bin/)
pybind11_add_module(_slsdet pybind11_add_module(_slsdet
src/main.cpp src/main.cpp
src/enums.cpp src/enums.cpp

View File

@ -57,6 +57,7 @@ foreach(exe ${MOENCH_EXECUTABLES})
../interpolations ../interpolations
../../slsReceiverSoftware/include/ ../../slsReceiverSoftware/include/
../../slsSupportLib/include/ ../../slsSupportLib/include/
${SLS_INTERNAL_RAPIDJSON_DIR}
) )
target_link_libraries(${exe} target_link_libraries(${exe}

View File

@ -17,6 +17,8 @@ add_library(slsDetectorObject OBJECT
target_include_directories(slsDetectorObject PUBLIC target_include_directories(slsDetectorObject PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
PRIVATE
${SLS_INTERNAL_RAPIDJSON_DIR}
) )
target_link_libraries(slsDetectorObject target_link_libraries(slsDetectorObject

View File

@ -40,6 +40,8 @@ add_library(slsReceiverObject OBJECT
target_include_directories(slsReceiverObject PUBLIC target_include_directories(slsReceiverObject PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
PRIVATE
${SLS_INTERNAL_RAPIDJSON_DIR}
) )
target_link_libraries(slsReceiverObject target_link_libraries(slsReceiverObject

View File

@ -34,6 +34,8 @@ set(PUBLICHEADERS
if(SLS_DEVEL_HEADERS) if(SLS_DEVEL_HEADERS)
set(PUBLICHEADERS set(PUBLICHEADERS
${PUBLICHEADERS} ${PUBLICHEADERS}
include/sls/ansi.h
include/sls/logger.h
include/sls/file_utils.h include/sls/file_utils.h
include/sls/sls_detector_funcs.h include/sls/sls_detector_funcs.h
include/sls/ClientSocket.h include/sls/ClientSocket.h
@ -46,7 +48,7 @@ if(SLS_DEVEL_HEADERS)
include/sls/versionAPI.h include/sls/versionAPI.h
include/sls/ZmqSocket.h include/sls/ZmqSocket.h
include/sls/bit_utils.h include/sls/bit_utils.h
include/sls/mdf5.h include/sls/md5.h
include/sls/md5_helper.h include/sls/md5_helper.h
) )
endif() endif()
@ -75,13 +77,16 @@ target_include_directories(slsSupportObject
PUBLIC PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
PRIVATE
${SLS_INTERNAL_RAPIDJSON_DIR}
) )
message(STATUS "RAPID: ${SLS_INTERNAL_RAPIDJSON_DIR}")
target_link_libraries(slsSupportObject target_link_libraries(slsSupportObject
PUBLIC PUBLIC
slsProjectOptions slsProjectOptions
libzmq libzmq
rapidjson
PRIVATE PRIVATE
slsProjectWarnings slsProjectWarnings
md5sls md5sls