diff --git a/CMakeLists.txt b/CMakeLists.txt index fbb7a76..c03953b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,14 +9,14 @@ 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") @@ -24,7 +24,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") else () set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_RELEASE "-O3") -endif() +endif () add_subdirectory(lib) add_subdirectory(bin) diff --git a/README.md b/README.md index b18db8a..465c79d 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # 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 @@ -15,7 +15,7 @@ Run following commands from project directory. cmake -S . -B cmake-build ``` -2. Build main target +2. Build executable target ```shell cmake --build cmake-build --target cpp_tests @@ -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: diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index 1beeaeb..c84570b 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -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}") diff --git a/install.sh b/install.sh index 34fd4d3..c568afc 100644 --- a/install.sh +++ b/install.sh @@ -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.' diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 8d0970f..4da245d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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}") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 40ba960..3edea0a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 @@ -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}")