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

perfect, dynamic libray suppart added

SOVERSION 1 used and requered
except for windoof!
This commit is contained in:
ClausKlein 2021-02-15 09:28:30 +01:00
parent fe76a4416c
commit 0322f4eeed
4 changed files with 13 additions and 11 deletions

View file

@ -20,7 +20,9 @@ endif()
# ---- Project settings ----
option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES)
if(NOT MSVC)
option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
@ -67,16 +69,15 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp)
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
# target! EITHER: add_library(Greeter INTERFACE) OR:
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:
# target_compile_options(Greeter PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive>") OR:
if(MSVC)
target_compile_options(Greeter PUBLIC /permissive)
endif()
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

@ -13,7 +13,6 @@ namespace greeter {
* @brief A class for saying hello in multiple languages
*/
class GREETER_EXPORT Greeter {
private:
std::string name;
public:

View file

@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.14...3.19)
project(GreeterTests LANGUAGES CXX)
project(
GreeterTests
VERSION 1
LANGUAGES CXX
)
# ---- Options ----

View file

@ -2,8 +2,6 @@
#include <greeter/greeter.h>
#include <greeter/version.h>
#include <string>
TEST_CASE("Greeter") {
using namespace greeter;
@ -17,8 +15,8 @@ TEST_CASE("Greeter") {
TEST_CASE("Greeter version") {
#if (__APPLE__ || __cpp_lib_starts_ends_with)
static_assert(std::string_view(GREETER_VERSION).starts_with("1.0")); // TBD C++20 only
CHECK(std::string(GREETER_VERSION).starts_with("1.0")); // SameMajorVersion
static_assert(std::string_view(GREETER_VERSION).starts_with("1")); // TBD C++20 only
CHECK(std::string(GREETER_VERSION).starts_with("1")); // SameMajorVersion
#else
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0.1"));
CHECK(std::string(GREETER_VERSION) == std::string("1.0.1"));