Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/ci_tests.yml
  • Loading branch information
bialger committed Aug 13, 2024
2 parents bbe7907 + 97c3d42 commit 8ff873b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ project(

set(CMAKE_CXX_STANDARD 20)

if(WIN32) # Install dlls in the same directory as the executable on Windows
if (WIN32) # Install dlls in the same directory as the executable on Windows
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
endif()
endif ()

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_DEBUG "/MDd")
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
else ()
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif()
endif ()

add_subdirectory(lib)
add_subdirectory(bin)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# C++ project template with Google Tests and CI/CD

This is a project template. Feel free to use & fork it. It contains all pre-configured
CMakeLists.txt, so to use it, just replace project name with your in
CMakeLists.txt, so to use it, replace project name with your one in
[main CmakeLists.txt](CMakeLists.txt), and all target and executable names in
[CI/CD script](./.github/workflows/ci_tests.yml). Sample program prints a greeting for the first argument.

## How to build and run

Run following commands from project directory.
Run the following commands from the project directory.

1. Create CMake cache

```shell
cmake -S . -B cmake-build
```

2. Build main target
2. Build executable target

```shell
cmake --build cmake-build --target cpp_tests
Expand All @@ -27,7 +27,7 @@ cmake --build cmake-build --target cpp_tests
cmake --build cmake-build --target cpp_tests_tests
```

4. Run main target
4. Run executable target

* On Windows:

Expand Down
4 changes: 2 additions & 2 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
add_executable(${PROJECT_NAME} main.cpp)

if(NOT CMAKE_BUILD_TYPE)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) # Main executable should be built with Release
endif()
endif ()

message(STATUS "Main executable build type: ${CMAKE_BUILD_TYPE}")

Expand Down
14 changes: 12 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@ if (cmake -S . -B "$CMAKE_PROJECT_DIR" -DCMAKE_BUILD_TYPE=Release -G "Unix Makef

exit 0
elif (cd "$CMAKE_PROJECT_DIR" && "./$PROJECT_NAME$EXEC_EXTENSION" -h >/dev/null 2>/dev/null); then
echo "Congratulations! $PROJECT_NAME was compiled successfully. But it is impossible to create a link to it - run it from $CMAKE_BUILD_DIR as .\\$PROJECT_NAME$EXEC_EXTENSION"
rm -f "$EXEC_LINK_PATH"
rm -rf "$HOME/${PROJECT_NAME:?}"
echo "Congratulations! $PROJECT_NAME was compiled successfully."
echo "Because of Windows-specific limitations, it is not possible to create a link to it."
echo "You can run it from $HOME/$PROJECT_NAME as .\\$PROJECT_NAME$EXEC_EXTENSION"
echo "Or you can run CMD.EXE with administrative privileges and type: "
echo 'mklink "%userprofile%\weather-forecast.exe" "%userprofile%\weather-forecast\weather-forecast.exe"'
echo ''
cd "$CMAKE_PROJECT_DIR" && "./$PROJECT_NAME$EXEC_EXTENSION" -h
mkdir "$HOME/$PROJECT_NAME"
cp "$CMAKE_PROJECT_DIR/$PROJECT_NAME$EXEC_EXTENSION" "$HOME/$PROJECT_NAME/$PROJECT_NAME$EXEC_EXTENSION"
# ALso copy all *dll files like following:
# cp -r "$CMAKE_PROJECT_DIR/liblib.dll" "$HOME/$PROJECT_NAME/liblib.dll"
cd "$HOME/$PROJECT_NAME" && "./$PROJECT_NAME$EXEC_EXTENSION" -h
exit 0
else
echo 'Oops! Could not execute the program.'
Expand Down
4 changes: 2 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.12)

if(NOT CMAKE_BUILD_TYPE)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) # Change this to Release when you're ready to release
endif()
endif ()

message(STATUS "Libraries build type: ${CMAKE_BUILD_TYPE}")

Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
GIT_TAG v1.15.2
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
Expand All @@ -29,9 +29,9 @@ target_link_libraries(
GTest::gtest_main
)

if(NOT CMAKE_BUILD_TYPE)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) # Tests should be built with Debug
endif()
endif ()

message(STATUS "Tests build type: ${CMAKE_BUILD_TYPE}")

Expand Down

0 comments on commit 8ff873b

Please sign in to comment.