Skip to content

Commit

Permalink
Implement interface library
Browse files Browse the repository at this point in the history
  • Loading branch information
mlund committed Nov 5, 2024
1 parent 4f8c03c commit c3608e6
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 55 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ example
unittests
_deps
html/
build/
.DS_Store
72 changes: 55 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -9,34 +20,61 @@ 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/[email protected]")
CPMAddPackage("gh:TheLartians/[email protected]")

# 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)
add_library(Eigen INTERFACE IMPORTED)
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 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

# Compile flags

# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(${PROJECT_NAME} INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/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)

24 changes: 12 additions & 12 deletions include/coulombgalore/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion include/coulombgalore/ewald.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
#pragma once

#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {

Expand Down
2 changes: 1 addition & 1 deletion include/coulombgalore/ewald_truncated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
#pragma once

#include "ewald.h"
#include "coulombgalore/ewald.hpp"

namespace CoulombGalore {

Expand Down
4 changes: 2 additions & 2 deletions include/coulombgalore/fanourgakis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {
/**
Expand Down Expand Up @@ -134,4 +134,4 @@ inline std::shared_ptr<SchemeBase> createScheme(const nlohmann::json &j) {
}
#endif

} // namespace CoulombGalore
} // namespace CoulombGalore
4 changes: 2 additions & 2 deletions include/coulombgalore/fennell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {
/**
Expand Down Expand Up @@ -81,4 +81,4 @@ class Fennell : public EnergyImplementation<Fennell> {
#endif
};

} // namespace CoulombGalore
} // namespace CoulombGalore
4 changes: 2 additions & 2 deletions include/coulombgalore/plain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {

Expand Down Expand Up @@ -56,4 +56,4 @@ class Plain : public EnergyImplementation<Plain> {
#endif
};

} // namespace CoulombGalore
} // namespace CoulombGalore
4 changes: 2 additions & 2 deletions include/coulombgalore/poisson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {
/**
Expand Down Expand Up @@ -231,4 +231,4 @@ class Poisson : public EnergyImplementation<Poisson> {
#endif
};

} // namespace CoulombGalore
} // namespace CoulombGalore
2 changes: 1 addition & 1 deletion include/coulombgalore/qpotential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {

Expand Down
4 changes: 2 additions & 2 deletions include/coulombgalore/reactionfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {
/**
Expand Down Expand Up @@ -85,4 +85,4 @@ class ReactionField : public EnergyImplementation<ReactionField> {
#endif
};

} // namespace CoulombGalore
} // namespace CoulombGalore
4 changes: 2 additions & 2 deletions include/coulombgalore/splined.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
#pragma once

#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {
namespace Tabulate {
Expand Down Expand Up @@ -385,4 +385,4 @@ class Splined : public EnergyImplementation<Splined> {
#endif
};

} // namespace CoulombGalore
} // namespace CoulombGalore
4 changes: 2 additions & 2 deletions include/coulombgalore/wolf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {
/**
Expand Down Expand Up @@ -79,4 +79,4 @@ class Wolf : public EnergyImplementation<Wolf> {
#endif
};

} // namespace CoulombGalore
} // namespace CoulombGalore
4 changes: 2 additions & 2 deletions include/coulombgalore/zahn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {
/**
Expand Down Expand Up @@ -84,4 +84,4 @@ class Zahn : public EnergyImplementation<Zahn> {
#endif
};

} // namespace CoulombGalore
} // namespace CoulombGalore
4 changes: 2 additions & 2 deletions include/coulombgalore/zerodipole.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#pragma once
#include "core.h"
#include "coulombgalore/core.hpp"

namespace CoulombGalore {
/**
Expand Down Expand Up @@ -89,4 +89,4 @@ class ZeroDipole : public EnergyImplementation<ZeroDipole> {
#endif
};

} // namespace CoulombGalore
} // namespace CoulombGalore
8 changes: 4 additions & 4 deletions test/example.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <iostream>
#include <nlohmann/json.hpp>
#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;

Expand Down
2 changes: 1 addition & 1 deletion test/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <doctest/doctest.h>
#include <nlohmann/json.hpp>
#include "coulombgalore/all.h"
#include "coulombgalore/all.hpp"

using namespace CoulombGalore;

Expand Down

0 comments on commit c3608e6

Please sign in to comment.