Files
bluelib/cmake/Templates.cmake

47 lines
1.8 KiB
CMake

function(add_bluelib_module)
set(options)
set(one_value_args NAME)
set(multi_value_args DEPENDENCIES)
cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${one_value_args}" "${multi_value_args}")
set(module_name ${arg_NAME})
file(GLOB sources *.c *.h)
file(GLOB sys_sources sys/${b_system_name}/*.c sys/${b_system_name}/*.h)
set(root_header include/blue/${module_name}.h)
file(GLOB headers include/blue/${module_name}/*.h)
add_library(blue-${module_name}-obj OBJECT ${sources} ${sys_sources} ${root_header} ${headers})
set_target_properties(blue-${module_name}-obj
PROPERTIES POSITION_INDEPENDENT_CODE ON)
string(REPLACE "-" "_" module_preproc_token ${module_name})
string(TOUPPER ${module_preproc_token} module_preproc_token)
set(module_preproc_token BLUELIB_${module_preproc_token})
target_include_directories(blue-${module_name}-obj PUBLIC include/)
target_compile_definitions(blue-${module_name}-obj PUBLIC ${module_preproc_token})
foreach (dep ${arg_DEPENDENCIES})
target_link_libraries(blue-${module_name}-obj blue-${dep}-obj)
endforeach (dep)
message(STATUS "Building module ${module_name} (shared)")
add_library(blue-${module_name} SHARED $<TARGET_OBJECTS:blue-${module_name}-obj>)
message(STATUS "Building module ${module_name} (static)")
add_library(blue-${module_name}-s STATIC $<TARGET_OBJECTS:blue-${module_name}-obj>)
target_include_directories(blue-${module_name} PUBLIC include/)
target_include_directories(blue-${module_name}-s PUBLIC include/)
foreach (dep ${arg_DEPENDENCIES})
target_link_libraries(blue-${module_name} blue-${dep})
target_link_libraries(blue-${module_name}-s blue-${dep}-s)
endforeach (dep)
install(TARGETS blue-${module_name} blue-${module_name}-s)
install(FILES ${root_header} DESTINATION include/blue)
install(FILES ${headers} DESTINATION include/blue/${module_name})
endfunction(add_bluelib_module)