merge with organizing targets

This commit is contained in:
Bechir 2024-03-08 13:28:34 +01:00
parent 47d381d299
commit 146d2aed19
7 changed files with 44 additions and 69 deletions

View File

@ -7,6 +7,9 @@ project(aare
LANGUAGES C CXX 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 CMP0135 NEW)
cmake_policy(SET CMP0079 NEW) cmake_policy(SET CMP0079 NEW)
@ -14,56 +17,30 @@ include(GNUInstallDirs)
include(FetchContent) 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_PYTHON_BINDINGS "Build python bindings" ON)
option(AARE_TESTS "Build tests" OFF) option(AARE_TESTS "Build tests" ON)
option(AARE_EXAMPLES "Build examples" OFF) option(AARE_EXAMPLES "Build examples" ON)
option(AARE_DEBUG "Compile in debug mode" ON)
#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)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(fmt 6 REQUIRED) 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(AARE_USE_WARNINGS)
target_compile_options(aare_compiler_flags INTERFACE -Wall -Wextra -pedantic -Wshadow )
# if (CMAKE_BUILD_TYPE STREQUAL "Debug") endif()
# 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_BUILD_TESTS) if(AARE_BUILD_TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(file_io) add_subdirectory(file_io)

View File

@ -7,17 +7,9 @@ set(SourceFiles
add_library(core STATIC ${SourceFiles}) add_library(core STATIC ${SourceFiles})
target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) 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) 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_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 set(SourceFiles
${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp
@ -13,18 +17,6 @@ set(SourceFiles
add_library(file_io STATIC ${SourceFiles}) add_library(file_io STATIC ${SourceFiles})
target_include_directories(file_io PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) 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) 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; File<detector,DataType>* f;
public: public:
FileHandler<detector,DataType>(std::filesystem::path fpath){ FileHandler<detector,DataType>(std::filesystem::path fname){
this->fpath = fpath; this->fpath = fname;
this->fileFactory= FileFactory<detector,DataType>::get_factory(fpath); this->fileFactory= FileFactory<detector,DataType>::get_factory(fname);
this->f= fileFactory->load_file(); this->f= fileFactory->load_file();
delete fileFactory; delete fileFactory;
} }

View File

@ -5,4 +5,4 @@ pybind11_add_module(_aare src/bindings.cpp)
set_target_properties(_aare PROPERTIES set_target_properties(_aare PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} 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(CTest)
include(Catch) 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()