CMake: Use interrogate's -import instead of linking directly

This commit is contained in:
Sam Edwards 2018-04-05 16:02:19 -06:00
parent 2f6c79b9e6
commit 411e0ee93f
3 changed files with 17 additions and 10 deletions

View File

@ -229,24 +229,34 @@ function(interrogate_sources target output database language_flags)
endfunction(interrogate_sources) endfunction(interrogate_sources)
# #
# Function: add_python_module(module [lib1 [lib2 ...]] [LINK lib1 ...]) # Function: add_python_module(module [lib1 [lib2 ...]] [LINK lib1 ...]
# [IMPORT mod1 ...])
# Uses interrogate to create a Python module. If the LINK keyword is specified, # Uses interrogate to create a Python module. If the LINK keyword is specified,
# the Python module is linked against the specified libraries instead of those # the Python module is linked against the specified libraries instead of those
# listed before. # listed before. The IMPORT keyword makes the output module import another
# Python module when it's initialized.
# #
function(add_python_module module) function(add_python_module module)
if(INTERROGATE_PYTHON_INTERFACE) if(INTERROGATE_PYTHON_INTERFACE)
set(targets) set(targets)
set(link_targets) set(link_targets)
set(import_flags)
set(infiles) set(infiles)
set(sources) set(sources)
set(link_keyword OFF) set(link_keyword OFF)
set(import_keyword OFF)
foreach(arg ${ARGN}) foreach(arg ${ARGN})
if(arg STREQUAL "LINK") if(arg STREQUAL "LINK")
set(link_keyword ON) set(link_keyword ON)
set(import_keyword OFF)
elseif(arg STREQUAL "IMPORT")
set(link_keyword OFF)
set(import_keyword ON)
elseif(link_keyword) elseif(link_keyword)
list(APPEND link_targets "${arg}") list(APPEND link_targets "${arg}")
elseif(import_keyword)
list(APPEND import_flags "-import" "${arg}")
else() else()
list(APPEND targets "${arg}") list(APPEND targets "${arg}")
endif() endif()
@ -269,6 +279,7 @@ function(add_python_module module)
COMMAND interrogate_module COMMAND interrogate_module
-oc "${CMAKE_CURRENT_BINARY_DIR}/${module}_module.cxx" -oc "${CMAKE_CURRENT_BINARY_DIR}/${module}_module.cxx"
-module ${module} -library ${module} -module ${module} -library ${module}
${import_flags}
${INTERROGATE_MODULE_OPTIONS} ${INTERROGATE_MODULE_OPTIONS}
${IMOD_FLAGS} ${infiles} ${IMOD_FLAGS} ${infiles}
DEPENDS interrogate_module ${infiles} DEPENDS interrogate_module ${infiles}

View File

@ -17,8 +17,7 @@ add_subdirectory(src/interval)
add_subdirectory(src/showbase) add_subdirectory(src/showbase)
if(HAVE_PYTHON) if(HAVE_PYTHON)
add_python_module(direct p3dcparser p3deadrec p3distributed p3interval p3showbase) add_python_module(direct p3dcparser p3deadrec p3distributed p3interval p3showbase IMPORT panda3d.core)
target_link_libraries(direct core)
# Make an __init__.py pointing at the source directory so users can run # Make an __init__.py pointing at the source directory so users can run
# Panda3D code straight from their build path: # Panda3D code straight from their build path:

View File

@ -96,15 +96,12 @@ if(HAVE_PYTHON)
add_python_module(core ${CORE_MODULE_COMPONENTS} LINK panda) add_python_module(core ${CORE_MODULE_COMPONENTS} LINK panda)
if(HAVE_EGG) if(HAVE_EGG)
add_python_module(egg p3egg p3egg2pg) add_python_module(egg p3egg p3egg2pg IMPORT panda3d.core)
target_link_libraries(egg core)
endif() endif()
add_python_module(physics p3physics p3particlesystem) add_python_module(physics p3physics p3particlesystem IMPORT panda3d.core)
target_link_libraries(physics core)
if(HAVE_ODE) if(HAVE_ODE)
add_python_module(ode p3ode) add_python_module(ode p3ode IMPORT panda3d.core)
target_link_libraries(ode core)
endif() endif()
endif() endif()