Skip to content

Commit

Permalink
made a cmakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Kay Freyer committed Nov 12, 2024
1 parent a6c1f81 commit e731f0e
Show file tree
Hide file tree
Showing 28 changed files with 699 additions and 940 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.cache/
/*.o
/libft.a
/build/
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.14)
project(libft)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()

# Flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")

file(GLOB SRC_FILES "src/*.c")
file(GLOB BONUS_SRC_FILES "src_bonus/*.c")
file(GLOB TEST_FILES "tests/*.cpp")

# Handle BUFFER_SIZE values
set(TEST_NAME "run_tests")
add_executable(${TEST_NAME} ${SRC_FILES} ${BONUS_SRC_FILES} ${TEST_FILES})

target_include_directories(${TEST_NAME} PRIVATE includes)
target_include_directories(${TEST_NAME} PRIVATE ${gtest_SOURCE_DIR}/googletest/include)

target_link_libraries(
${TEST_NAME}
GTest::gtest
GTest::gtest_main
pthread
bsd
)


# find_package(PkgConfig REQUIRED)
# pkg_check_modules(LIBBSD REQUIRED libbsd)

# # Link the library to your target
# target_link_libraries(${TEST_NAME} ${LIBBSD_LIBRARIES})

# Register the test with CTest
include(GoogleTest)
gtest_discover_tests(${TEST_NAME})
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CFLAGS := -Wall -Wextra -Werror
CFLAGS += -Iincludes
CXXFLAGS := -Wall -Wextra
CXXFLAGS += -Iincludes
LDFLAGS := -Lgtest -lgtest -lgtest_main -pthread
LDFLAGS := -lgtest -lgtest_main -pthread
BSD := -lbsd

# Test Flags
Expand Down
Loading

0 comments on commit e731f0e

Please sign in to comment.