Skip to content

Commit c67f84b

Browse files
authored
Merge pull request #2 from emrekovanci/develop
2 parents 5bc7fc8 + 7b5f590 commit c67f84b

File tree

10 files changed

+84
-19
lines changed

10 files changed

+84
-19
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
build:
10-
name: ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.build_type }}
10+
name: ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.build_type }} ${{ matrix.config.name }}
1111
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
1212
runs-on: ${{ matrix.os }}
1313
timeout-minutes: 120
@@ -25,6 +25,9 @@ jobs:
2525
build_type:
2626
- Debug
2727
- Release
28+
config:
29+
- { name: Shared, flags: -DBUILD_SHARED_LIBS=TRUE }
30+
- { name: Static, flags: -DBUILD_SHARED_LIBS=FALSE }
2831

2932
exclude:
3033
- os: windows-2022
@@ -36,9 +39,19 @@ jobs:
3639
- os: windows-2022
3740
compiler: msvc
3841
build_type: Debug
42+
config: { name: Shared, flags: -DBUILD_SHARED_LIBS=TRUE }
43+
- os: windows-2022
44+
compiler: msvc
45+
build_type: Debug
46+
config: { name: Static, flags: -DBUILD_SHARED_LIBS=FALSE }
3947
- os: windows-2022
4048
compiler: msvc
4149
build_type: Release
50+
config: { name: Shared, flags: -DBUILD_SHARED_LIBS=TRUE }
51+
- os: windows-2022
52+
compiler: msvc
53+
build_type: Release
54+
config: { name: Static, flags: -DBUILD_SHARED_LIBS=FALSE }
4255

4356
steps:
4457
- name: Checkout Code
@@ -59,9 +72,9 @@ jobs:
5972
shell: bash
6073
run: |
6174
if [ "${{ runner.os }}" == "Windows" ]; then
62-
cmake --preset=Windows-${{ matrix.compiler }}-${{ matrix.build_type }}
75+
cmake --preset=Windows-${{ matrix.compiler }}-${{ matrix.build_type }} ${{ matrix.config.flags }}
6376
else
64-
cmake --preset=${{ matrix.compiler }}-${{ matrix.build_type }}
77+
cmake --preset=${{ matrix.compiler }}-${{ matrix.build_type }} ${{ matrix.config.flags }}
6578
fi
6679
6780
- name: CMake Build
@@ -72,6 +85,16 @@ jobs:
7285
else
7386
cmake --build --preset=${{ matrix.compiler }}-${{ matrix.build_type }}
7487
fi
88+
89+
- name: Install
90+
shell: bash
91+
run: |
92+
if [ "${{ runner.os }}" == "Windows" ]; then
93+
cmake --install out/build/Windows-${{ matrix.compiler }}-${{ matrix.build_type }} --prefix prefix
94+
else
95+
cmake --install out/build/${{ matrix.compiler }}-${{ matrix.build_type }} --prefix prefix
96+
fi
97+
7598
- name: Test
7699
if: ${{ matrix.build_type == 'Debug' }}
77100
shell: bash

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cmake_minimum_required(VERSION 3.26)
22

3+
include(cmake/PreventInSourceBuilds.cmake)
4+
35
project(
46
Template-CPP
57
VERSION 0.1.0

CMakePresets.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545
"inherits": "confs-windows-common",
4646
"cacheVariables": {
4747
"CMAKE_CXX_COMPILER": "cl",
48-
"CMAKE_CXX_FLAGS": "/diagnostics:caret /utf-8 /sdl /w14165 /w44242 /w44254 /w44263 /w34265 /w34287 /w44296 /w44388 /w44464 /w14545 /w14546 /w14547 /w14549 /w14555 /w34619 /w34640 /w24826 /w14905 /w14906 /w14928 /w45038 /W4 /permissive- /volatile:iso /Zc:inline /Zc:preprocessor /Zc:enumTypes /Zc:lambda /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew /EHsc",
49-
"CMAKE_EXE_LINKER_FLAGS": "/machine:x64"
48+
"CMAKE_CXX_FLAGS": "/sdl /guard:cf /utf-8 /diagnostics:caret /sdl /w14165 /w44242 /w44254 /w44263 /w34265 /w34287 /w44296 /w44388 /w44464 /w14545 /w14546 /w14547 /w14549 /w14555 /w34619 /w34640 /w24826 /w14905 /w14906 /w14928 /w45038 /W4 /permissive- /volatile:iso /Zc:inline /Zc:preprocessor /Zc:enumTypes /Zc:lambda /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew /EHsc",
49+
"CMAKE_EXE_LINKER_FLAGS": "/machine:x64 /guard:cf",
50+
"CMAKE_SHARED_LINKER_FLAGS": "/machine:x64 /guard:cf"
5051
},
5152
"vendor": {
5253
"microsoft.com/VisualStudioSettings/CMake/1.0": {

app/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Define executable and its properties
1+
# ---- Define executable ----
2+
23
add_executable(Application App.cpp)
34
target_link_libraries(Application PRIVATE Core)
4-
set_target_properties(Application PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Application)
55
install(TARGETS Application)

cmake/PreventInSourceBuilds.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ---- In-source guard ----
2+
3+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
4+
message(
5+
FATAL_ERROR
6+
"In-source builds are not supported. "
7+
"You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first."
8+
)
9+
endif()

library/CMakeLists.txt

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,37 @@ set(LIBRARY_SOURCES
1010
${SRCROOT}/Lib.cpp
1111
)
1212

13-
# Define library and its properties
14-
add_library(Core STATIC ${LIBRARY_HEADERS} ${LIBRARY_SOURCES})
13+
# ---- Define library ----
14+
add_library(Core ${LIBRARY_HEADERS} ${LIBRARY_SOURCES})
1515
target_include_directories(Core PUBLIC ${PROJECT_SOURCE_DIR}/library/include)
1616
target_compile_features(Core PUBLIC cxx_std_17)
17+
18+
include(GenerateExportHeader)
19+
generate_export_header(Core
20+
EXPORT_FILE_NAME Core_Export.h
21+
EXPORT_MACRO_NAME CORE_API
22+
NO_EXPORT_MACRO_NAME CORE_PRIVATE
23+
)
24+
target_sources(Core
25+
PUBLIC
26+
FILE_SET HEADERS
27+
BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR}
28+
FILES ${CMAKE_CURRENT_BINARY_DIR}/Core_Export.h
29+
)
30+
31+
if(NOT BUILD_SHARED_LIBS)
32+
target_compile_definitions(Core PUBLIC CORE_STATIC_DEFINE)
33+
endif()
34+
35+
set_target_properties(Core PROPERTIES
36+
CXX_VISIBILITY_PRESET hidden
37+
VISIBILITY_INLINES_HIDDEN YES
38+
VERSION "${PROJECT_VERSION}"
39+
SOVERSION "${PROJECT_VERSION_MAJOR}"
40+
)
41+
1742
install(TARGETS Core)
1843

1944
if (FEATURE_TESTS)
2045
add_subdirectory(${PROJECT_SOURCE_DIR}/library/test)
2146
endif()
22-
23-
# Group headers and sources for IDE
24-
source_group(TREE ${INCROOT} PREFIX "Headers" FILES ${LIBRARY_HEADERS})
25-
source_group(TREE ${SRCROOT} PREFIX "Sources" FILES ${LIBRARY_SOURCES})

library/include/Core/Lib.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#pragma once
22

3+
#include "Core_Export.h"
4+
35
#include <string>
46

5-
struct Lib
7+
struct CORE_API Lib
68
{
79
Lib();
810

library/test/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
# ---- Dependencies ----
2+
13
include(Catch)
4+
set(CMAKE_CATCH_DISCOVER_TESTS_DISCOVERY_MODE PRE_TEST)
5+
6+
# ---- Define executable ----
27

3-
add_executable(CoreTests ${PROJECT_SOURCE_DIR}/library/test/Tests.cpp)
8+
add_executable(CoreTests Tests.cpp)
49
target_link_libraries(CoreTests PRIVATE Core Catch2::Catch2WithMain)
510
target_compile_features(CoreTests PRIVATE cxx_std_17)
6-
set_target_properties(CoreTests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Core/Tests)
7-
catch_discover_tests(CoreTests)
11+
12+
# ---- Tests ----
13+
14+
catch_discover_tests(CoreTests WORKING_DIRECTORY $<TARGET_FILE_DIR:Core>)

vcpkg-configuration.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"default-registry": {
44
"kind": "git",
55
"repository": "https://github.com/microsoft/vcpkg",
6-
"baseline": "13c3c0fcc203d179f4443fe48d252e3ff220cbeb"
6+
"baseline": "6c87aab05cb2ebd1c9e382167edf3b15a7718e70"
77
}
88
}

vcpkg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependencies": [
1313
{
1414
"name": "catch2",
15-
"version>=": "3.4.0"
15+
"version>=": "3.5.0"
1616
}
1717
]
1818
}

0 commit comments

Comments
 (0)