CMake: Generate Shared And Static Libraries At Same Time

By creating 2 targets and set same OUTPUT_NAME for both targets:

1
2
3
4
5
6
7
8
9
10
11
add_library(v4l2capturer-shared SHARED ${V4L2CAPTURER_SRC})
target_include_directories(v4l2capturer-shared PRIVATE ${LIBV4L2_INCLUDE_DIRS})
target_include_directories(v4l2capturer-shared PUBLIC ${V4L2CAPTURER_INC})
set_target_properties(v4l2capturer-shared PROPERTIES OUTPUT_NAME v4l2capturer)
target_link_libraries(v4l2capturer-shared PRIVATE ${LIBV4L2_LIBRARIES})

add_library(v4l2capturer-static STATIC ${V4L2CAPTURER_SRC})
target_include_directories(v4l2capturer-static PRIVATE ${LIBV4L2_INCLUDE_DIRS})
target_include_directories(v4l2capturer-static PUBLIC ${V4L2CAPTURER_INC})
set_target_properties(v4l2capturer-static PROPERTIES OUTPUT_NAME v4l2capturer)
target_link_libraries(v4l2capturer-static PRIVATE ${LIBV4L2_LIBRARIES})