cmake_minimum_required( VERSION 1.21 ) project( simple_object_library_test ) set( USE_OBJECT_LIBRARIES 1 ) function( my_add_library the_library ) if( USE_OBJECT_LIBRARIES ) add_library( ${the_library} OBJECT ) else() add_library( ${the_library} ) endif() endfunction() # Library A my_add_library( a ) target_sources( a PRIVATE files_a/a.c ) target_include_directories( a PUBLIC files_a ) # Library B my_add_library( b ) target_sources( b PRIVATE files_b/b.c ) target_include_directories( b PUBLIC files_b ) target_link_libraries( b PUBLIC a ) # Main add_executable( main ) add_executable( main_all ) target_sources( main PRIVATE main.c ) target_sources( main_all PRIVATE main.c ) target_link_libraries( main PUBLIC b ) target_link_libraries( main_all PUBLIC b a )