diff --git a/CMakeLists.txt b/CMakeLists.txt index 933a528..b6fbd68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 35d808d..b79651f 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -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() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b2954b2..23b1284 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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) + diff --git a/file_io/CMakeLists.txt b/file_io/CMakeLists.txt index b223605..abccbbb 100644 --- a/file_io/CMakeLists.txt +++ b/file_io/CMakeLists.txt @@ -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() diff --git a/file_io/include/aare/FileHandler.hpp b/file_io/include/aare/FileHandler.hpp index c28e681..709d0e4 100644 --- a/file_io/include/aare/FileHandler.hpp +++ b/file_io/include/aare/FileHandler.hpp @@ -10,9 +10,9 @@ class FileHandler{ File* f; public: - FileHandler(std::filesystem::path fpath){ - this->fpath = fpath; - this->fileFactory= FileFactory::get_factory(fpath); + FileHandler(std::filesystem::path fname){ + this->fpath = fname; + this->fileFactory= FileFactory::get_factory(fname); this->f= fileFactory->load_file(); delete fileFactory; } diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 6f5300e..ef40eed 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -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) \ No newline at end of file +target_link_libraries(_aare PRIVATE aare aare_compiler_flags) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4a2d076..26c8e4e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,4 +17,16 @@ set_target_properties(tests PROPERTIES include(CTest) include(Catch) -catch_discover_tests(tests) \ No newline at end of file +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() \ No newline at end of file