diff --git a/.gitignore b/.gitignore index ecc0efa..d130aa0 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ example unittests _deps html/ +build/ +.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index e6befca..abfcd7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,17 @@ -cmake_minimum_required(VERSION 3.11.4 FATAL_ERROR) +# Based in https://github.com/TheLartians/ModernCppStarter/blob/master/CMakeLists.txt -project(coulombgalore) +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +project(coulombgalore VERSION 0.1.2 LANGUAGES CXX) + +# ---- Include guards ---- + +if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + message( + FATAL_ERROR + "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there." + ) +endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED YES) @@ -9,20 +20,11 @@ enable_testing() include(cmake/CPM.cmake) -## GCC -if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - add_compile_options(-Wall -Wextra -Wpedantic -Wunreachable-code -Wstrict-aliasing) -## Clang -elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wall -Wextra -Wpedantic -Wunreachable-code -Wstrict-aliasing) -endif() - # dependencies - CPMAddPackage("gh:doctest/doctest#v2.4.11") CPMAddPackage("gh:nlohmann/json@3.11.3") +CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.12.0") -# Eigen CPMAddPackage(NAME Eigen VERSION 3.4.0 DOWNLOAD_ONLY YES URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz) if(Eigen_ADDED) @@ -30,13 +32,49 @@ if(Eigen_ADDED) target_include_directories(Eigen INTERFACE ${Eigen_SOURCE_DIR}) endif() -include_directories(${CMAKE_SOURCE_DIR}/include) +file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp") -add_executable(example test/example.cpp) -target_link_libraries(example Eigen nlohmann_json) +add_library(${PROJECT_NAME} INTERFACE ${headers}) +set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17) +target_link_libraries(${PROJECT_NAME} INTERFACE Eigen) -add_executable(tests test/unittests.cpp) -target_link_libraries(tests doctest Eigen nlohmann_json) +target_include_directories( + ${PROJECT_NAME} INTERFACE $ + $ +) +# Compile flags + +# being a cross-platform target, we enforce standards conformance on MSVC +target_compile_options(${PROJECT_NAME} INTERFACE "$<$:/permissive->") + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + add_compile_options(-Wall -Wextra -Wpedantic -Wunreachable-code -Wstrict-aliasing) +elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic -Wunreachable-code -Wstrict-aliasing) +endif() + +# the location where the project's version header will be placed should match the project's regular +# header paths +string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION) + +packageProject( + NAME ${PROJECT_NAME} + VERSION ${PROJECT_VERSION} + NAMESPACE ${PROJECT_NAME} + BINARY_DIR ${PROJECT_BINARY_DIR} + INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include + INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} + VERSION_HEADER "${VERSION_HEADER_LOCATION}" + DEPENDENCIES "eigen 3" +) + +# example +add_executable(example EXCLUDE_FROM_ALL test/example.cpp) +target_link_libraries(example ${PROJECT_NAME} nlohmann_json) + +# unittests +add_executable(tests test/unittests.cpp) +target_link_libraries(tests ${PROJECT_NAME} doctest Eigen nlohmann_json) add_test(NAME tests COMMAND tests) diff --git a/include/coulombgalore/all.h b/include/coulombgalore/all.hpp similarity index 80% rename from include/coulombgalore/all.h rename to include/coulombgalore/all.hpp index 0d0fb69..57df327 100644 --- a/include/coulombgalore/all.h +++ b/include/coulombgalore/all.hpp @@ -24,15 +24,15 @@ */ #pragma once -#include "ewald.h" -#include "ewald_truncated.h" -#include "fanourgakis.h" -#include "fennell.h" -#include "plain.h" -#include "poisson.h" -#include "qpotential.h" -#include "reactionfield.h" -#include "splined.h" -#include "wolf.h" -#include "zahn.h" -#include "zerodipole.h" +#include "ewald.hpp" +#include "ewald_truncated.hpp" +#include "fanourgakis.hpp" +#include "fennell.hpp" +#include "plain.hpp" +#include "poisson.hpp" +#include "qpotential.hpp" +#include "reactionfield.hpp" +#include "splined.hpp" +#include "wolf.hpp" +#include "zahn.hpp" +#include "zerodipole.hpp" diff --git a/include/coulombgalore/core.h b/include/coulombgalore/core.hpp similarity index 100% rename from include/coulombgalore/core.h rename to include/coulombgalore/core.hpp diff --git a/include/coulombgalore/ewald.h b/include/coulombgalore/ewald.hpp similarity index 99% rename from include/coulombgalore/ewald.h rename to include/coulombgalore/ewald.hpp index c027fdc..85de873 100644 --- a/include/coulombgalore/ewald.h +++ b/include/coulombgalore/ewald.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { diff --git a/include/coulombgalore/ewald_truncated.h b/include/coulombgalore/ewald_truncated.hpp similarity index 99% rename from include/coulombgalore/ewald_truncated.h rename to include/coulombgalore/ewald_truncated.hpp index c12307e..0c00e72 100644 --- a/include/coulombgalore/ewald_truncated.h +++ b/include/coulombgalore/ewald_truncated.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "ewald.h" +#include "coulombgalore/ewald.hpp" namespace CoulombGalore { diff --git a/include/coulombgalore/fanourgakis.h b/include/coulombgalore/fanourgakis.hpp similarity index 98% rename from include/coulombgalore/fanourgakis.h rename to include/coulombgalore/fanourgakis.hpp index 9e8b20e..603f589 100644 --- a/include/coulombgalore/fanourgakis.h +++ b/include/coulombgalore/fanourgakis.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { /** @@ -134,4 +134,4 @@ inline std::shared_ptr createScheme(const nlohmann::json &j) { } #endif -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/include/coulombgalore/fennell.h b/include/coulombgalore/fennell.hpp similarity index 98% rename from include/coulombgalore/fennell.h rename to include/coulombgalore/fennell.hpp index 852c967..32d9a09 100644 --- a/include/coulombgalore/fennell.h +++ b/include/coulombgalore/fennell.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { /** @@ -81,4 +81,4 @@ class Fennell : public EnergyImplementation { #endif }; -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/include/coulombgalore/plain.h b/include/coulombgalore/plain.hpp similarity index 97% rename from include/coulombgalore/plain.h rename to include/coulombgalore/plain.hpp index 5716d00..9608260 100644 --- a/include/coulombgalore/plain.h +++ b/include/coulombgalore/plain.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { @@ -56,4 +56,4 @@ class Plain : public EnergyImplementation { #endif }; -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/include/coulombgalore/poisson.h b/include/coulombgalore/poisson.hpp similarity index 99% rename from include/coulombgalore/poisson.h rename to include/coulombgalore/poisson.hpp index f1eec9b..cdfb739 100644 --- a/include/coulombgalore/poisson.h +++ b/include/coulombgalore/poisson.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { /** @@ -231,4 +231,4 @@ class Poisson : public EnergyImplementation { #endif }; -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/include/coulombgalore/qpotential.h b/include/coulombgalore/qpotential.hpp similarity index 99% rename from include/coulombgalore/qpotential.h rename to include/coulombgalore/qpotential.hpp index 9466670..77ad273 100644 --- a/include/coulombgalore/qpotential.h +++ b/include/coulombgalore/qpotential.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { diff --git a/include/coulombgalore/reactionfield.h b/include/coulombgalore/reactionfield.hpp similarity index 98% rename from include/coulombgalore/reactionfield.h rename to include/coulombgalore/reactionfield.hpp index b7549ac..91dbe21 100644 --- a/include/coulombgalore/reactionfield.h +++ b/include/coulombgalore/reactionfield.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { /** @@ -85,4 +85,4 @@ class ReactionField : public EnergyImplementation { #endif }; -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/include/coulombgalore/splined.h b/include/coulombgalore/splined.hpp similarity index 99% rename from include/coulombgalore/splined.h rename to include/coulombgalore/splined.hpp index c05da42..0c7da15 100644 --- a/include/coulombgalore/splined.h +++ b/include/coulombgalore/splined.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { namespace Tabulate { @@ -385,4 +385,4 @@ class Splined : public EnergyImplementation { #endif }; -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/include/coulombgalore/wolf.h b/include/coulombgalore/wolf.hpp similarity index 98% rename from include/coulombgalore/wolf.h rename to include/coulombgalore/wolf.hpp index 9c1b89c..45dae33 100644 --- a/include/coulombgalore/wolf.h +++ b/include/coulombgalore/wolf.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { /** @@ -79,4 +79,4 @@ class Wolf : public EnergyImplementation { #endif }; -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/include/coulombgalore/zahn.h b/include/coulombgalore/zahn.hpp similarity index 98% rename from include/coulombgalore/zahn.h rename to include/coulombgalore/zahn.hpp index b969d26..f75f19f 100644 --- a/include/coulombgalore/zahn.h +++ b/include/coulombgalore/zahn.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { /** @@ -84,4 +84,4 @@ class Zahn : public EnergyImplementation { #endif }; -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/include/coulombgalore/zerodipole.h b/include/coulombgalore/zerodipole.hpp similarity index 98% rename from include/coulombgalore/zerodipole.h rename to include/coulombgalore/zerodipole.hpp index d4e69ef..58e2fcb 100644 --- a/include/coulombgalore/zerodipole.h +++ b/include/coulombgalore/zerodipole.hpp @@ -24,7 +24,7 @@ */ #pragma once -#include "core.h" +#include "coulombgalore/core.hpp" namespace CoulombGalore { /** @@ -89,4 +89,4 @@ class ZeroDipole : public EnergyImplementation { #endif }; -} // namespace CoulombGalore \ No newline at end of file +} // namespace CoulombGalore diff --git a/test/example.cpp b/test/example.cpp index 4564ec6..59bae93 100644 --- a/test/example.cpp +++ b/test/example.cpp @@ -1,9 +1,9 @@ #include #include -#include "coulombgalore/plain.h" -#include "coulombgalore/qpotential.h" -#include "coulombgalore/fanourgakis.h" -#include "coulombgalore/ewald.h" +#include "coulombgalore/plain.hpp" +#include "coulombgalore/qpotential.hpp" +#include "coulombgalore/fanourgakis.hpp" +#include "coulombgalore/ewald.hpp" using namespace CoulombGalore; diff --git a/test/unittests.cpp b/test/unittests.cpp index 7bf5021..0bb2fd5 100644 --- a/test/unittests.cpp +++ b/test/unittests.cpp @@ -5,7 +5,7 @@ #include #include -#include "coulombgalore/all.h" +#include "coulombgalore/all.hpp" using namespace CoulombGalore;