CMake: Make directbase/pandabase INTERFACE libraries

They export no code, and are really only used to contain several
preprocessor macros relevant to their respective packages. On
Windows, they're a problem: MSVC doesn't generate a .lib when
compiling a .dll that exports nothing.
This commit is contained in:
Sam Edwards 2018-06-10 01:46:36 -06:00
parent 4ea42666d6
commit 2e98b68e3b
4 changed files with 19 additions and 16 deletions

View File

@ -30,24 +30,29 @@ function(target_link_libraries target)
set_property(TARGET "${target}" APPEND PROPERTY INCLUDE_DIRECTORIES "${include_directories}")
set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${include_directories}")
# Also build with the same BUILDING_ macros, because these will all end
# up in the same library.
set(compile_definitions "$<$<BOOL:$<TARGET_PROPERTY:${library},IS_COMPONENT>>:$<TARGET_PROPERTY:${library},COMPILE_DEFINITIONS>>")
set_property(TARGET "${target}" APPEND PROPERTY COMPILE_DEFINITIONS "${compile_definitions}")
# Libraries are only linked transitively if they aren't components.
# Unfortunately, it seems like INTERFACE_LINK_LIBRARIES can't have
# generator expressions on an object library(?) so we resort to taking
# care of this at configuration time.
if(TARGET "${library}")
get_target_property(is_component "${library}" IS_COMPONENT)
get_target_property(target_type "${library}" TYPE)
if(NOT target_type STREQUAL "INTERFACE_LIBRARY")
get_target_property(is_component "${library}" IS_COMPONENT)
else()
set(is_component OFF)
endif()
else()
# This is a safe assumption, since we define all component libraries
# before the metalib they appear in:
set(is_component OFF)
endif()
if(NOT is_component)
if(is_component)
# Also build with the same BUILDING_ macros, because these will all end
# up in the same library.
set(compile_definitions "$<TARGET_PROPERTY:${library},COMPILE_DEFINITIONS>")
set_property(TARGET "${target}" APPEND PROPERTY COMPILE_DEFINITIONS "${compile_definitions}")
else()
set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${library}")
endif()
else()

View File

@ -15,7 +15,7 @@ add_subdirectory(src/motiontrail)
add_subdirectory(src/showbase)
set(P3DIRECT_COMPONENTS
p3dcparser p3deadrec p3directbase
p3dcparser p3deadrec
p3interval p3motiontrail p3showbase)
if(HAVE_PYTHON)
list(APPEND P3DIRECT_COMPONENTS p3distributed)

View File

@ -6,10 +6,8 @@ set(P3DIRECTBASE_HEADERS
directbase.h directsymbols.h
)
# Not worth compositing sources, there's really only one.
add_component_library(p3directbase NOINIT
${P3DIRECTBASE_HEADERS} ${P3DIRECTBASE_SOURCES})
target_link_libraries(p3directbase panda)
# Yes, INTERFACE: don't build it, there's no code!
add_library(p3directbase INTERFACE)
target_link_libraries(p3directbase INTERFACE panda)
install(TARGETS p3directbase DESTINATION lib)
install(FILES ${P3DIRECTBASE_HEADERS} DESTINATION include/panda3d)

View File

@ -6,8 +6,8 @@ set(P3PANDABASE_SOURCES
pandabase.cxx
)
add_component_library(p3pandabase ${P3PANDABASE_HEADERS} ${P3PANDABASE_SOURCES})
target_link_libraries(p3pandabase p3dtool)
# Yes, INTERFACE: don't build it, there's no code!
add_library(p3pandabase INTERFACE)
target_link_libraries(p3pandabase INTERFACE p3dtool)
install(TARGETS p3pandabase DESTINATION lib)
install(FILES ${P3PANDABASE_HEADERS} DESTINATION include/panda3d)