From 3fe29c70beb4361dea189a868ba59f9dae813256 Mon Sep 17 00:00:00 2001 From: bialger Date: Thu, 18 Jan 2024 14:37:12 +0300 Subject: [PATCH] Added build types for tests and main --- CMakeLists.txt | 8 ++++++++ bin/CMakeLists.txt | 6 ++++++ lib/CMakeLists.txt | 8 -------- tests/CMakeLists.txt | 6 ++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2db2daa..2c522d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,14 @@ project( set(CMAKE_CXX_STANDARD 20) +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() + add_subdirectory(lib) add_subdirectory(bin) diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index 9fd306f..bb5b4fc 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -1,5 +1,11 @@ add_executable(${PROJECT_NAME} main.cpp) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) # Main executable should be built with Release +endif() + +message(STATUS "Main executable build type: ${CMAKE_BUILD_TYPE}") + target_link_libraries(${PROJECT_NAME} PUBLIC mylib) target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) \ No newline at end of file diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 0a896ac..167c4c7 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,14 +4,6 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) # Change this to Release when you're ready to release 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() - message(STATUS "Libraries build type: ${CMAKE_BUILD_TYPE}") add_subdirectory(mylib) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4c62957..f5b1680 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,6 +23,12 @@ target_link_libraries( GTest::gtest_main ) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug) # Tests should be built with Debug +endif() + +message(STATUS "Tests build type: ${CMAKE_BUILD_TYPE}") + target_include_directories(${PROJECT_NAME}_tests PUBLIC ${PROJECT_SOURCE_DIR}) include(GoogleTest)