添加googletest

This commit is contained in:
2024-09-16 08:56:03 +08:00
parent b1893c001e
commit 5ffc8c8eb0

View File

@@ -1,30 +1,41 @@
cmake_minimum_required(VERSION 3.30) cmake_minimum_required(VERSION 3.30)
project(leetcode C) project(leetcode C CXX)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include_directories(include) include_directories(include)
include(FetchContent)
add_compile_options( add_compile_options(
-Wall -Wall
-Wextra -Wextra
-O0 -O0
-g3 -g3
-fsanitize=address -fsanitize=address
-fsanitize=undefined -fsanitize=undefined
-fno-omit-frame-pointer -fno-omit-frame-pointer
) )
add_link_options( add_link_options(
-fsanitize=address -fsanitize=address
-fsanitize=undefined -fsanitize=undefined
) )
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/releases/download/v1.15.2/googletest-1.15.2.tar.gz
URL_HASH MD5=7e11f6cfcf6498324ac82d567dcb891e
)
FetchContent_MakeAvailable(googletest)
file(GLOB SRC_FILES "src/*.c") file(GLOB SRC_FILES "src/*.c")
foreach(SRC_FILE ${SRC_FILES}) foreach (SRC_FILE ${SRC_FILES})
get_filename_component(EXE_NAME ${SRC_FILE} NAME_WE) get_filename_component(EXE_NAME ${SRC_FILE} NAME_WE)
add_executable(${EXE_NAME} ${SRC_FILE}) add_executable(${EXE_NAME} ${SRC_FILE})
endforeach() endforeach ()
add_subdirectory(tests)