Files
spark/cmake/InitSharedLibrary.cmake
T

31 lines
1.2 KiB
CMake

function(init_shared_library source_dir)
file(
GLOB_RECURSE ${PROJECT_NAME}_Sources
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${source_dir}/*.cpp)
# Note: cpp files inside 'tests' dir(s) are considered tests.
# Remove tests from main sources, and add them to test sources
set(${PROJECT_NAME}_Test_Sources)
foreach(item ${${PROJECT_NAME}_Sources})
if(${item} MATCHES "tests/*.cpp")
list(REMOVE_ITEM ${PROJECT_NAME}_Sources ${item})
list(APPEND ${PROJECT_NAME}_Test_Sources ${item})
endif()
endforeach()
# Add main library
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_Sources})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# target_include_directories(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:$<CONFIG>/include>)
# Add tests executable (if there are any)
if (${PROJECT_NAME}_Test_Sources)
add_executable(${PROJECT_NAME}-tests ${${PROJECT_NAME}_Test_Sources})
target_link_libraries(${PROJECT_NAME}-tests PRIVATE ${PROJECT_NAME})
# Catch2
find_package(Catch2 CONFIG REQUIRED COMPONENTS Catch2WithMain)
target_link_libraries(${PROJECT_NAME}-tests PRIVATE Catch2::Catch2WithMain)
endif()
endfunction(init_shared_library)