File size: 1,051 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Function to add a library target.
function(custom_add_library_from_dir TARGET)
    # Gather files from the current directory
    file(GLOB TARGET_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
    add_library(${TARGET} ${TARGET_SRC})
endfunction()

# Function to add an executable target.
function(custom_add_executable_from_dir TARGET)
    # Gather files from the current directory
    file(GLOB TARGET_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
    add_executable(${TARGET} ${TARGET_SRC})
endfunction()

# Function to add an executable target containing tests for a library.
function(custom_add_test_from_dir TARGET LIBRARY)
    custom_add_executable_from_dir(${TARGET})
    # Add path to Catch framework header
    target_include_directories(${TARGET} PRIVATE "${CMAKE_SOURCE_DIR}/libs/catch")
    # Link with the library being tested
    target_link_libraries(${TARGET} ${LIBRARY})
    # Register the executable with CMake as a test set
    add_test(${TARGET} ${TARGET})
endfunction()