Skip to content

Commit

Permalink
Added build types for tests and main
Browse files Browse the repository at this point in the history
  • Loading branch information
bialger committed Jan 18, 2024
1 parent 4991ea5 commit 3fe29c7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
8 changes: 0 additions & 8 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3fe29c7

Please sign in to comment.