Browse Source

CMake: Consolidate "module or static" library logic

Sam Edwards 7 years ago
parent
commit
8e230495a1

+ 2 - 6
cmake/macros/Interrogate.cmake

@@ -237,7 +237,7 @@ endfunction(interrogate_sources)
 # Python module when it's initialized.
 # Python module when it's initialized.
 #
 #
 function(add_python_module module)
 function(add_python_module module)
-  if(INTERROGATE_PYTHON_INTERFACE)
+  if(HAVE_PYTHON AND INTERROGATE_PYTHON_INTERFACE)
     set(targets)
     set(targets)
     set(link_targets)
     set(link_targets)
     set(import_flags)
     set(import_flags)
@@ -286,11 +286,7 @@ function(add_python_module module)
       COMMENT "Generating module ${module}"
       COMMENT "Generating module ${module}"
     )
     )
 
 
-    if(BUILD_SHARED_LIBS)
-      add_library(${module} MODULE "${module}_module.cxx" ${sources})
-    else()
-      add_library(${module} STATIC "${module}_module.cxx" ${sources})
-    endif()
+    add_library(${module} ${MODULE_TYPE} "${module}_module.cxx" ${sources})
     target_link_libraries(${module}
     target_link_libraries(${module}
       ${link_targets} ${PYTHON_LIBRARIES} p3dtool)
       ${link_targets} ${PYTHON_LIBRARIES} p3dtool)
 
 

+ 5 - 0
dtool/LocalSetup.cmake

@@ -180,10 +180,15 @@ check_cxx_compiler_flag(-msse2 HAVE_SSE2)
 #$[cdefine __USE_LARGEFILE64]
 #$[cdefine __USE_LARGEFILE64]
 
 
 # Set LINK_ALL_STATIC if we're building everything as static libraries.
 # Set LINK_ALL_STATIC if we're building everything as static libraries.
+# Also set the library type used for "modules" appropriately.
 if(BUILD_SHARED_LIBS)
 if(BUILD_SHARED_LIBS)
   set(LINK_ALL_STATIC OFF)
   set(LINK_ALL_STATIC OFF)
+  set(MODULE_TYPE "MODULE"
+    CACHE INTERNAL "" FORCE)
 else()
 else()
   set(LINK_ALL_STATIC ON)
   set(LINK_ALL_STATIC ON)
+  set(MODULE_TYPE "STATIC"
+    CACHE INTERNAL "" FORCE)
 endif()
 endif()
 
 
 # Now go through all the packages and report whether we have them.
 # Now go through all the packages and report whether we have them.

+ 1 - 7
dtool/metalibs/dtoolconfig/CMakeLists.txt

@@ -6,12 +6,6 @@ install(TARGETS p3dtoolconfig DESTINATION lib)
 
 
 # Next, panda3d.interrogatedb:
 # Next, panda3d.interrogatedb:
 
 
-if(BUILD_SHARED_LIBS)
-  set(libtype MODULE)
-else()
-  set(libtype STATIC)
-endif()
-
 if(HAVE_PYTHON AND INTERROGATE_PYTHON_INTERFACE)
 if(HAVE_PYTHON AND INTERROGATE_PYTHON_INTERFACE)
   set(INTERROGATEDB_IGATE
   set(INTERROGATEDB_IGATE
     ../../src/interrogatedb/interrogate_interface.h
     ../../src/interrogatedb/interrogate_interface.h
@@ -33,7 +27,7 @@ if(HAVE_PYTHON AND INTERROGATE_PYTHON_INTERFACE)
     COMMENT "Interrogating interrogatedb"
     COMMENT "Interrogating interrogatedb"
   )
   )
 
 
-  add_library(interrogatedb ${libtype}
+  add_library(interrogatedb ${MODULE_TYPE}
     "${CMAKE_CURRENT_BINARY_DIR}/interrogatedb_module.cxx")
     "${CMAKE_CURRENT_BINARY_DIR}/interrogatedb_module.cxx")
   target_use_packages(interrogatedb PYTHON)
   target_use_packages(interrogatedb PYTHON)
   target_link_libraries(interrogatedb p3dtoolconfig)
   target_link_libraries(interrogatedb p3dtoolconfig)