From 2e98b68e3bbcba08de428f7a0c20427d547803cf Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sun, 10 Jun 2018 01:46:36 -0600 Subject: [PATCH] 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. --- cmake/macros/BuildMetalib.cmake | 19 ++++++++++++------- direct/CMakeLists.txt | 2 +- direct/src/directbase/CMakeLists.txt | 8 +++----- panda/src/pandabase/CMakeLists.txt | 6 +++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cmake/macros/BuildMetalib.cmake b/cmake/macros/BuildMetalib.cmake index 7b804bd1b9..716f8c09d8 100644 --- a/cmake/macros/BuildMetalib.cmake +++ b/cmake/macros/BuildMetalib.cmake @@ -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 "$<$>:$>") - 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 "$") + set_property(TARGET "${target}" APPEND PROPERTY COMPILE_DEFINITIONS "${compile_definitions}") + else() set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${library}") endif() else() diff --git a/direct/CMakeLists.txt b/direct/CMakeLists.txt index 14ea20eca3..9e6e238d03 100644 --- a/direct/CMakeLists.txt +++ b/direct/CMakeLists.txt @@ -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) diff --git a/direct/src/directbase/CMakeLists.txt b/direct/src/directbase/CMakeLists.txt index 447c93f12d..53a8de1ee7 100644 --- a/direct/src/directbase/CMakeLists.txt +++ b/direct/src/directbase/CMakeLists.txt @@ -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) diff --git a/panda/src/pandabase/CMakeLists.txt b/panda/src/pandabase/CMakeLists.txt index 4e9b89735c..3cf44a1228 100644 --- a/panda/src/pandabase/CMakeLists.txt +++ b/panda/src/pandabase/CMakeLists.txt @@ -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)