Merge pull request #13 from slsdetectorgroup/organizing-flags

Organizing flags
This commit is contained in:
Erik Fröjdh 2024-03-08 14:32:43 +01:00 committed by GitHub
commit dfb298aaeb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 44 additions and 69 deletions

View File

@ -7,6 +7,9 @@ project(aare
LANGUAGES C CXX
)
add_library(aare_compiler_flags INTERFACE)
target_compile_features(aare_compiler_flags INTERFACE cxx_std_17)
cmake_policy(SET CMP0135 NEW)
cmake_policy(SET CMP0079 NEW)
@ -14,56 +17,30 @@ include(GNUInstallDirs)
include(FetchContent)
option(AARE_USE_SANITIZER "Sanitizers for debugging" ON)
option(AARE_USE_WARNINGS "Eable warnings" ON)
option(AARE_PYTHON_BINDINGS "Build python bindings" ON)
option(AARE_TESTS "Build tests" OFF)
option(AARE_EXAMPLES "Build examples" OFF)
#TODO! Should this be on the top level or move it down to the component
#that needs it?
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(json)
option(AARE_TESTS "Build tests" ON)
option(AARE_EXAMPLES "Build examples" ON)
option(AARE_DEBUG "Compile in debug mode" ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(fmt 6 REQUIRED)
if (AARE_DEBUG)
target_compile_options(aare_compiler_flags INTERFACE -Og -ggdb3 -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC)
else()
target_compile_options(aare_compiler_flags INTERFACE -O3)
endif()
# set(CMAKE_BUILD_TYPE "Debug")
# if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# set(OPTIMIZATION_FLAGS "-Og -ggdb3 -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC")
# else()
# set(OPTIMIZATION_FLAGS "-O3")
# endif()
# set(OPTIONAL_FLAGS "")
# if(DISABLE_WARNINGS)
# set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow -Wformat=2 -Wold-style-cast -Wnon-virtual-dtor -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Woverloaded-virtual -Winline")
# endif()
# if(USE_SANITIZER)
# set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -fdiagnostics-parseable-fixits -fdiagnostics-generate-patch -fdiagnostics-show-template-tree -fsanitize=address,undefined,pointer-compare -fno-sanitize-recover -D_FORTIFY_SOURCE=2 -fstack-protector -fno-omit-frame-pointer ")
# endif()
# set(SUPPRESSED_WARNINGS "-Wno-return-type")
# set(CMAKE_CXX_FLAGS "${OPTIMIZATION_FLAGS} ${SUPPRESSED_WARNINGS}")
if(AARE_USE_WARNINGS)
target_compile_options(aare_compiler_flags INTERFACE -Wall -Wextra -pedantic -Wshadow )
endif()
if(AARE_BUILD_TESTS)
add_subdirectory(tests)
endif()
add_subdirectory(core)
add_subdirectory(file_io)

View File

@ -7,17 +7,9 @@ set(SourceFiles
add_library(core STATIC ${SourceFiles})
target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(core PUBLIC fmt::fmt)
target_link_libraries(core PUBLIC fmt::fmt PRIVATE aare_compiler_flags)
set_property(TARGET core PROPERTY POSITION_INDEPENDENT_CODE ON)
if(AARE_BUILD_TESTS)
set(TestSources
${CMAKE_CURRENT_SOURCE_DIR}/src/defs.test.cpp
)
target_sources(tests PRIVATE ${TestSources} )
#Work around to remove, this is not the way to do it =)
# target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include/common)
target_link_libraries(tests PRIVATE core)
endif()

View File

@ -2,5 +2,7 @@ add_executable(example "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
target_include_directories(example PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(example PRIVATE aare_compiler_flags)

View File

@ -1,4 +1,8 @@
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(json)
set(SourceFiles
${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp
@ -13,18 +17,6 @@ set(SourceFiles
add_library(file_io STATIC ${SourceFiles})
target_include_directories(file_io PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(file_io PUBLIC fmt::fmt core nlohmann_json::nlohmann_json)
target_link_libraries(file_io PRIVATE fmt::fmt core nlohmann_json::nlohmann_json aare_compiler_flags)
set_property(TARGET file_io PROPERTY POSITION_INDEPENDENT_CODE ON)
# if(AARE_BUILD_TESTS)
# set(TestSources
# ${CMAKE_CURRENT_SOURCE_DIR}/src/defs.test.cpp
# )
# target_sources(tests PRIVATE ${TestSources} )
# #Work around to remove, this is not the way to do it =)
# # target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include/common)
# target_link_libraries(tests PRIVATE file_io)
# endif()

View File

@ -10,9 +10,9 @@ class FileHandler{
File<detector,DataType>* f;
public:
FileHandler<detector,DataType>(std::filesystem::path fpath){
this->fpath = fpath;
this->fileFactory= FileFactory<detector,DataType>::get_factory(fpath);
FileHandler<detector,DataType>(std::filesystem::path fname){
this->fpath = fname;
this->fileFactory= FileFactory<detector,DataType>::get_factory(fname);
this->f= fileFactory->load_file();
delete fileFactory;
}

View File

@ -5,4 +5,4 @@ pybind11_add_module(_aare src/bindings.cpp)
set_target_properties(_aare PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
target_link_libraries(_aare PRIVATE aare)
target_link_libraries(_aare PRIVATE aare aare_compiler_flags)

View File

@ -17,4 +17,16 @@ set_target_properties(tests PROPERTIES
include(CTest)
include(Catch)
catch_discover_tests(tests)
catch_discover_tests(tests)
if(AARE_BUILD_TESTS)
set(TestSources
${CMAKE_CURRENT_SOURCE_DIR}/src/defs.test.cpp
)
target_sources(tests PRIVATE ${TestSources} )
#Work around to remove, this is not the way to do it =)
# target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include/common)
target_link_libraries(tests PRIVATE core aare_compiler_flags)
endif()