build: add template for c++-based modules
This commit is contained in:
@@ -105,3 +105,118 @@ function(add_bluelib_module)
|
|||||||
install(FILES ${root_header} DESTINATION include/blue)
|
install(FILES ${root_header} DESTINATION include/blue)
|
||||||
install(FILES ${headers} DESTINATION include/blue/${module_name})
|
install(FILES ${headers} DESTINATION include/blue/${module_name})
|
||||||
endfunction(add_bluelib_module)
|
endfunction(add_bluelib_module)
|
||||||
|
|
||||||
|
function(add_bluelib_mm_module)
|
||||||
|
set(options)
|
||||||
|
set(one_value_args NAME)
|
||||||
|
set(multi_value_args
|
||||||
|
DEPENDENCIES
|
||||||
|
SUBDIRS
|
||||||
|
EXTRA_SOURCES
|
||||||
|
LIBS
|
||||||
|
INCLUDE_DIRS
|
||||||
|
DEFINES)
|
||||||
|
cmake_parse_arguments(PARSE_ARGV 0 arg
|
||||||
|
"${options}"
|
||||||
|
"${one_value_args}"
|
||||||
|
"${multi_value_args}")
|
||||||
|
|
||||||
|
set(short_module_name ${arg_NAME})
|
||||||
|
set(module_name ${arg_NAME}-mm)
|
||||||
|
|
||||||
|
file(GLOB sources
|
||||||
|
*.c *.h
|
||||||
|
*.cpp *.hpp)
|
||||||
|
|
||||||
|
foreach (dir ${arg_SUBDIRS})
|
||||||
|
file(GLOB dir_sources
|
||||||
|
${dir}/*.c ${dir}/*.h
|
||||||
|
${dir}/*.cpp ${dir}/*.hpp)
|
||||||
|
set(sources ${sources} ${dir_sources})
|
||||||
|
endforeach (dir)
|
||||||
|
|
||||||
|
file(GLOB sys_sources
|
||||||
|
sys/${b_system_name}/*.c sys/${b_system_name}/*.h
|
||||||
|
sys/${b_system_name}/*.cpp sys/${b_system_name}/*.hpp)
|
||||||
|
set(root_header include/blue/${short_module_name}.hpp)
|
||||||
|
file(GLOB headers include/blue/${short_module_name}/*.hpp)
|
||||||
|
|
||||||
|
string(REPLACE "-" "_" module_preproc_token ${short_module_name})
|
||||||
|
string(TOUPPER ${module_preproc_token} module_preproc_token)
|
||||||
|
set(module_preproc_token BLUELIB_${module_preproc_token})
|
||||||
|
|
||||||
|
message(STATUS "Building mm module ${short_module_name} (shared)")
|
||||||
|
add_library(blue-${module_name} SHARED
|
||||||
|
${sources}
|
||||||
|
${sys_sources}
|
||||||
|
${root_header}
|
||||||
|
${headers}
|
||||||
|
${arg_EXTRA_SOURCES})
|
||||||
|
message(STATUS "Building mm module ${short_module_name} (static)")
|
||||||
|
add_library(blue-${module_name}-s STATIC
|
||||||
|
${sources}
|
||||||
|
${sys_sources}
|
||||||
|
${root_header}
|
||||||
|
${headers}
|
||||||
|
${arg_EXTRA_SOURCES})
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
foreach (lib ${arg_LIBS})
|
||||||
|
target_link_libraries(blue-${module_name} ${lib})
|
||||||
|
target_link_libraries(blue-${module_name}-s ${lib})
|
||||||
|
endforeach (lib)
|
||||||
|
|
||||||
|
foreach (dir ${arg_INCLUDE_DIRS})
|
||||||
|
target_include_directories(blue-${module_name} PRIVATE
|
||||||
|
${dir})
|
||||||
|
target_include_directories(blue-${module_name}-s PRIVATE
|
||||||
|
${dir})
|
||||||
|
endforeach (dir)
|
||||||
|
|
||||||
|
foreach (def ${arg_DEFINES})
|
||||||
|
target_compile_definitions(blue-${module_name} PRIVATE
|
||||||
|
${def})
|
||||||
|
target_compile_definitions(blue-${module_name}-s PRIVATE
|
||||||
|
${def})
|
||||||
|
endforeach (def)
|
||||||
|
|
||||||
|
set_target_properties(blue-${module_name} PROPERTIES
|
||||||
|
FOLDER "mm/Shared/${short_module_name}")
|
||||||
|
set_target_properties(blue-${module_name}-s PROPERTIES
|
||||||
|
FOLDER "mm/Static/${short_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/${short_module_name})
|
||||||
|
endfunction(add_bluelib_mm_module)
|
||||||
|
|||||||
Reference in New Issue
Block a user