1
0
Fork 0
mirror of https://github.com/TheLartians/ModernCppStarter.git synced 2025-08-30 21:51:12 +02:00

one more try with dll on windows

cleanup code too
This commit is contained in:
ClausKlein 2021-02-16 18:25:02 +01:00
parent d7a5e850a0
commit f59c0cfbee
4 changed files with 10 additions and 22 deletions

View file

@ -20,9 +20,9 @@ endif()
# ---- Project settings ----
if(NOT MSVC)
option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES)
endif()
# XXX if(NOT MSVC)
option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES)
# XXX endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
@ -44,12 +44,9 @@ CPMUsePackageLock(package-lock.cmake)
CPMAddPackage(
NAME PackageProject.cmake
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
VERSION 1.4.1
VERSION 1.5.0
)
# Note: If fmt is not imported, this is needed to prevent: CMake Error: install(EXPORT
# "GreeterTargets" ...) includes target "Greeter" which requires target "fmt" that is not in any
# export set. see too https://gitlab.kitware.com/cmake/cmake/-/issues/15415
CPMAddPackage(
NAME fmt
GIT_TAG 7.1.3
@ -71,13 +68,10 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp)
add_library(Greeter ${headers} ${sources})
set_target_properties(Greeter PROPERTIES SOVERSION 1 VERSION ${PROJECT_VERSION})
# EITHER:
set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
# OR: target_compile_features(Greeter PUBLIC cxx_std_20)
# being a cross-platform target, we enforce standards conformance on MSVC EITHER:
# being a cross-platform target, we enforce standards conformance on MSVC:
target_compile_options(Greeter PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive>")
# OR: if(MSVC) target_compile_options(Greeter PUBLIC /permissive) endif()
# Link dependencies EITHER:
target_link_libraries(Greeter PRIVATE $<BUILD_INTERFACE:fmt::fmt-header-only>)

View file

@ -7,12 +7,12 @@
namespace greeter {
/** Language codes to be used with the Greeter class */
enum class GREETER_EXPORT LanguageCode { EN, DE, ES, FR };
enum class LanguageCode { EN, DE, ES, FR };
/**
* @brief A class for saying hello in multiple languages
*/
class GREETER_EXPORT Greeter {
class Greeter {
std::string name;
public:
@ -20,14 +20,15 @@ namespace greeter {
* @brief Creates a new greeter
* @param name the name to greet
*/
explicit Greeter(std::string _name);
explicit GREETER_EXPORT Greeter(std::string _name);
/**
* @brief Creates a localized string containing the greeting
* @param lang the language to greet in
* @return a string containing the greeting
*/
[[nodiscard]] auto greet(LanguageCode lang = LanguageCode::EN) const -> std::string;
[[nodiscard]] auto GREETER_EXPORT greet(LanguageCode lang = LanguageCode::EN) const
-> std::string;
};
} // namespace greeter

View file

@ -8,8 +8,6 @@
// NOLINTNEXTLINE(modernize-use-trailing-return-type)
int main(int argc, char** argv) {
// prevent warning: initialization of 'languages' with static storage duration may throw an
// exception that cannot be caught [cert-err58-cpp]
const std::unordered_map<std::string, greeter::LanguageCode> languages{
{"en", greeter::LanguageCode::EN},
{"de", greeter::LanguageCode::DE},
@ -17,8 +15,6 @@ int main(int argc, char** argv) {
{"fr", greeter::LanguageCode::FR},
};
// prevent warning: do not use pointer arithmetic
// [cppcoreguidelines-pro-bounds-pointer-arithmetic]
cxxopts::Options options(*argv, "A program to welcome the world!");
std::string language;
@ -40,7 +36,6 @@ int main(int argc, char** argv) {
return 0;
}
// prevent warning: do not use 'else' after 'return' [readability-else-after-return]
if (result["version"].as<bool>()) {
std::cout << "Greeter, version " << GREETER_VERSION << std::endl;
return 0;

View file

@ -45,9 +45,7 @@ CPMAddPackage(
file(GLOB sources CONFIGURE_DEPENDS source/*.cpp)
add_executable(GreeterTests ${sources})
target_link_libraries(GreeterTests doctest::doctest Greeter::Greeter)
# EITHER:
set_target_properties(GreeterTests PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
# OR: target_compile_features(GreeterTests PUBLIC cxx_std_20)
# enable compiler warnings
if(NOT TEST_INSTALLED_VERSION)