Skip to content

Commit d6245e3

Browse files
author
Markus Wippler
committed
Initial commit
0 parents  commit d6245e3

File tree

12 files changed

+171
-0
lines changed

12 files changed

+171
-0
lines changed

.clang-format

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
BasedOnStyle: LLVM
3+
ColumnLimit: 120
4+
IndentWidth: 4
5+
TabWidth: 4
6+
UseTab: ForIndentation
7+
8+
BreakBeforeBraces: Custom
9+
BraceWrapping:
10+
AfterFunction: true
11+
SplitEmptyRecord: false
12+
13+
AlignEscapedNewlines: DontAlign
14+
AllowShortFunctionsOnASingleLine: Inline
15+
AlwaysBreakTemplateDeclarations: true
16+
BreakBeforeBinaryOperators: NonAssignment
17+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
18+
PointerAlignment: Left
19+
...

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.{c,cpp,h,hpp,inc}]
10+
indent_style = tab
11+
indent_size = 4

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.lib filter=lfs diff=lfs merge=lfs -text
2+
*.pdb filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build*
2+
.vscode

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "external/fmt"]
2+
path = external/fmt
3+
url = https://github.com/fmtlib/fmt.git
4+
[submodule "external/catch2"]
5+
path = external/catch2
6+
url = https://github.com/catchorg/Catch2.git

CMakeLists.txt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
3+
cmake_policy(SET CMP0091 NEW) # MSVC_RUNTIME_LIBRARY
4+
5+
project(libenvpp LANGUAGES CXX)
6+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
7+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
8+
9+
# Determine if libenvpp is built as a subproject (using add_subdirectory).
10+
if (NOT DEFINED LIBENVPP_MASTER_PROJECT)
11+
set(LIBENVPP_MASTER_PROJECT OFF)
12+
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
13+
set(LIBENVPP_MASTER_PROJECT ON)
14+
endif()
15+
endif()
16+
17+
# Set CMAKE_MSVC_RUNTIME_LIBRARY to its supposed default value. This is needed
18+
# by external dependencies to correctly support builds on Windows using Clang.
19+
if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
20+
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>DLL)
21+
endif()
22+
23+
option(LIBENVPP_TESTS "Build libenvpp tests" ${LIBENVPP_MASTER_PROJECT})
24+
25+
include(cmake/libenvpp_mt_utils.cmake)
26+
27+
# Function for setting compiler-specific parameters.
28+
function(libenvpp_set_compiler_parameters TARGET)
29+
set_target_properties(${TARGET} PROPERTIES
30+
CXX_STANDARD 17
31+
CXX_EXTENSIONS OFF
32+
)
33+
target_compile_options(${TARGET} PRIVATE
34+
$<$<CXX_COMPILER_ID:MSVC>:/D_CRT_SECURE_NO_WARNINGS /MP /W4 /permissive- /bigobj /Zi /utf-8>
35+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -pedantic -g>
36+
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color>
37+
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>
38+
)
39+
target_link_options(${TARGET} PRIVATE
40+
$<$<CXX_COMPILER_ID:MSVC>:/DEBUG /ignore:4099>
41+
)
42+
target_compile_definitions(${TARGET} PUBLIC
43+
$<$<BOOL:${WIN32}>:LIBENVPP_PLATFORM_WINDOWS>
44+
)
45+
endfunction()
46+
47+
# External dependencies.
48+
option(BUILD_SHARED_LIBS "Build shared libs" OFF)
49+
set(CMAKE_FOLDER "external/fmt")
50+
add_subdirectory(external/fmt)
51+
if(LIBENVPP_TESTS)
52+
set(CMAKE_FOLDER "external/catch2")
53+
add_subdirectory(external/catch2)
54+
include("external/catch2/extras/Catch.cmake")
55+
endif()
56+
unset(CMAKE_FOLDER)
57+
58+
# libenvpp library.
59+
set(LIBENVPP_SOURCES
60+
"source/libenvpp.cpp"
61+
)
62+
63+
# Add includes to library so they show up in IDEs.
64+
file(GLOB_RECURSE LIBENVPP_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
65+
66+
add_library(libenvpp STATIC ${LIBENVPP_SOURCES} ${LIBENVPP_INCLUDES})
67+
libenvpp_set_compiler_parameters(libenvpp)
68+
target_link_libraries(libenvpp PUBLIC fmt::fmt)
69+
target_include_directories(libenvpp PUBLIC
70+
"${CMAKE_CURRENT_SOURCE_DIR}/include"
71+
)
72+
73+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${LIBENVPP_SOURCES} ${LIBENVPP_INCLUDES})
74+
75+
# Unit tests.
76+
if(LIBENVPP_TESTS)
77+
include(CTest)
78+
add_executable(libenvpp_tests
79+
"test/libenvpp_test.cpp"
80+
)
81+
libenvpp_set_compiler_parameters(libenvpp_tests)
82+
target_link_libraries(libenvpp_tests PRIVATE libenvpp Catch2::Catch2WithMain)
83+
84+
# Set test as VS startup if libenvpp is master project.
85+
if(LIBENVPP_MASTER_PROJECT)
86+
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT libenvpp_tests)
87+
endif()
88+
89+
catch_discover_tests(libenvpp_tests)
90+
endif()

cmake/libenvpp_mt_utils.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(libenvpp_target_mt $<STREQUAL:$<GENEX_EVAL:$<TARGET_PROPERTY:MSVC_RUNTIME_LIBRARY>>,MultiThreaded>)
2+
set(libenvpp_target_mtd $<STREQUAL:$<GENEX_EVAL:$<TARGET_PROPERTY:MSVC_RUNTIME_LIBRARY>>,MultiThreadedDebug>)
3+
set(libenvpp_target_static_runtime $<OR:${libenvpp_target_mt},${libenvpp_target_mtd}>)
4+
set(libenvpp_mt_suffix $<${libenvpp_target_static_runtime}:_mt>)

external/catch2

Submodule catch2 added at 97c48e0

external/fmt

Submodule fmt added at c4ee726

include/libenvpp.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
namespace env {
4+
5+
extern const char* HELLO_WORLD;
6+
7+
int test();
8+
9+
} // namespace env

0 commit comments

Comments
 (0)