light/tools/cmake/functions.cmake

70 lines
2.5 KiB
CMake
Raw Normal View History

function (add_library_module libname)
2025-07-05 13:28:41 +03:30
if ("${ARGN}" STREQUAL "") # Header only library
message("Adding INTERFACE library ${libname}")
add_library(${libname} INTERFACE)
target_include_directories(${libname} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Do not link base against base :D
if (NOT ${libname} STREQUAL "base")
target_link_libraries(${libname} INTERFACE base)
endif ()
2025-07-05 13:28:41 +03:30
else () # Compiled library
set(source_files)
set(source_directory "${CMAKE_CURRENT_SOURCE_DIR}/src")
foreach (source_file ${ARGN})
list(APPEND source_files "${source_directory}/${source_file}")
endforeach ()
message("Adding library ${libname} with source files: ${source_files}")
add_library(${libname} ${source_files})
target_include_directories(${libname} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Do not link base against base :D
if (NOT ${libname} STREQUAL "base")
target_link_libraries(${libname} PUBLIC base)
endif ()
2025-07-05 13:28:41 +03:30
endif ()
endfunction ()
2025-07-05 13:28:41 +03:30
function (add_executable_module exename)
2025-07-05 13:28:41 +03:30
set(source_files)
set(source_directory "${CMAKE_CURRENT_SOURCE_DIR}/src")
foreach (source_file ${ARGN})
list(APPEND source_files "${source_directory}/${source_file}")
endforeach ()
message("Adding executable ${exename} with source files: ${source_files}")
add_executable(${exename} ${source_files})
2025-07-16 10:36:07 +03:30
target_include_directories(${exename} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${exename} PRIVATE base)
endfunction ()
function (add_test_module exename)
if (NOT ${ENABLE_TESTS})
return()
endif ()
2025-07-16 10:36:07 +03:30
set(source_files)
set(source_directory "${CMAKE_CURRENT_SOURCE_DIR}/src")
foreach (source_file ${ARGN})
list(APPEND source_files "${source_directory}/${source_file}")
endforeach ()
message("Adding test executable ${exename}_tests with source files: ${source_files}")
add_executable(${exename}_tests ${source_files})
target_include_directories(${exename} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${exename}_tests PRIVATE ${exename} base test)
endfunction ()
function (add_option option help)
option(${option} ${help})
if (${option})
message(STATUS "${option}: ON")
add_compile_definitions(${option}=1)
else ()
message(STATUS "${option}: OFF")
endif ()
endfunction ()