38 lines
1.0 KiB
CMake
38 lines
1.0 KiB
CMake
cmake_minimum_required(VERSION 3.25)
|
|
project(leetcode)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
include(FetchContent)
|
|
FetchContent_Declare(
|
|
googletest
|
|
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
|
)
|
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
FetchContent_MakeAvailable(googletest)
|
|
include(GoogleTest)
|
|
|
|
set(SOURCES)
|
|
file(GLOB_RECURSE SOURCES "src/*/*.cpp")
|
|
|
|
enable_testing()
|
|
|
|
# Iterate over each source file
|
|
message(STATUS "========= enable_testing ========")
|
|
foreach(SOURCE ${SOURCES})
|
|
# Get the file name without extension
|
|
get_filename_component(APP_NAME ${SOURCE} NAME_WE)
|
|
|
|
message(STATUS "==== app_name: ${APP_NAME} path: ${SOURCE}")
|
|
# Add an executable target for each file
|
|
add_executable(${APP_NAME} ${SOURCE})
|
|
target_link_libraries(
|
|
${APP_NAME}
|
|
GTest::gtest_main
|
|
)
|
|
|
|
gtest_discover_tests(${APP_NAME})
|
|
endforeach()
|
|
message(STATUS "========= end testing ========")
|