Files
bluelib/cmake/Templates.cmake

59 lines
2.4 KiB
CMake

function(add_bluelib_module)
set(options)
set(one_value_args NAME)
set(multi_value_args DEPENDENCIES SUBDIRS)
cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${one_value_args}" "${multi_value_args}")
set(module_name ${arg_NAME})
file(GLOB sources *.c *.h)
foreach (dir ${arg_SUBDIRS})
file(GLOB dir_sources ${dir}/*.c ${dir}/*.h)
set(sources ${sources} ${dir_sources})
endforeach (dir)
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)
string(REPLACE "-" "_" module_preproc_token ${module_name})
string(TOUPPER ${module_preproc_token} module_preproc_token)
set(module_preproc_token BLUELIB_${module_preproc_token})
message(STATUS "Building module ${module_name} (shared)")
add_library(blue-${module_name} SHARED ${sources} ${sys_sources} ${root_header} ${headers})
message(STATUS "Building module ${module_name} (static)")
add_library(blue-${module_name}-s STATIC ${sources} ${sys_sources} ${root_header} ${headers})
target_include_directories(blue-${module_name} PUBLIC include/)
target_include_directories(blue-${module_name}-s PUBLIC include/)
target_compile_definitions(blue-${module_name} PUBLIC ${module_preproc_token} BLUELIB_EXPORT=1)
target_compile_definitions(blue-${module_name}-s PUBLIC ${module_preproc_token} BLUELIB_EXPORT=1 BLUELIB_STATIC=1)
set_target_properties(blue-${module_name}
PROPERTIES POSITION_INDEPENDENT_CODE ON)
foreach (dep ${arg_DEPENDENCIES})
target_link_libraries(blue-${module_name} blue-${dep})
target_link_libraries(blue-${module_name}-s blue-${dep}-s)
endforeach (dep)
set_target_properties(blue-${module_name} PROPERTIES FOLDER "Shared/${module_name}")
set_target_properties(blue-${module_name}-s PROPERTIES FOLDER "Static/${module_name}")
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
target_compile_definitions(blue-${module_name} PRIVATE BIG_ENDIAN)
target_compile_definitions(blue-${module_name}-s PRIVATE BIG_ENDIAN)
else()
target_compile_definitions(blue-${module_name} PRIVATE LITTLE_ENDIAN)
target_compile_definitions(blue-${module_name}-s PRIVATE LITTLE_ENDIAN)
endif()
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)