11function (add_python_extension name )
22 parse_arguments (ADD_PYTHON_EXTENSION
33 "REQUIRES;SOURCES;LIBRARIES;INCLUDEDIRS"
4- ""
4+ "BUILTIN "
55 ${ARGN}
66 )
77
8+ # Remove _ from the beginning of the name.
9+ string (REGEX REPLACE "^_" "" pretty_name "${name} " )
10+
11+ # Upper case the name.
12+ string (TOUPPER "${pretty_name} " upper_name)
13+
14+ # Add a prefix to the target name so it doesn't clash with any system
15+ # libraries that we might want to link against (eg. readline)
16+ set (target_name extension_${pretty_name} )
17+
18+ # Add options that the user can set to control whether this extension is
19+ # compiled, and whether it is compiled in to libpython itself.
20+ option (ENABLE_${upper_name}
21+ "Controls whether the \" ${name} \" extension will be built"
22+ ON
23+ )
24+ option (BUILTIN_${upper_name}
25+ "If this is set the \" ${name} \" extension will be compiled in to libpython"
26+ ${ADD_PYTHON_EXTENSION_BUILTIN}
27+ )
28+
829 # Check all the things we require are found.
930 set (missing_deps "" )
10- foreach (dep ${ADD_PYTHON_EXTENSION_REQUIRES} )
31+ foreach (dep ${ADD_PYTHON_EXTENSION_REQUIRES} ENABLE_ ${upper_name} )
1132 if (NOT ${dep} )
1233 set (missing_deps "${missing_deps}${dep} " )
1334 endif (NOT ${dep} )
@@ -23,10 +44,6 @@ function(add_python_extension name)
2344 set (extensions_enabled "${extensions_enabled}${name} ;" CACHE INTERNAL "" FORCE )
2445 endif (missing_deps )
2546
26- # Add a prefix to the target name so it doesn't clash with any system
27- # libraries that we might want to link against (eg. readline)
28- set (target_name extension_${name} )
29-
3047 # Callers to this function provide source files relative to the Modules/
3148 # directory. We need to get absolute paths for them all.
3249 set (absolute_sources "" )
@@ -41,17 +58,25 @@ function(add_python_extension name)
4158 endif (${ext} STREQUAL ".S" )
4259 endforeach (source )
4360
44- add_library (${target_name} SHARED ${absolute_sources} )
45- include_directories (${ADD_PYTHON_EXTENSION_INCLUDEDIRS} )
46- target_link_libraries (${target_name} ${ADD_PYTHON_EXTENSION_LIBRARIES} )
61+ if (BUILTIN_${upper_name} )
62+ # This will be compiled into libpython instead of as a separate library
63+ set (builtin_extensions "${builtin_extensions}${name} ;" CACHE INTERNAL "" FORCE )
64+ set (builtin_source "${builtin_source}${absolute_sources} ;" CACHE INTERNAL "" FORCE )
65+ else (BUILTIN_${upper_name} )
66+ add_library (${target_name} SHARED ${absolute_sources} )
67+ include_directories (${ADD_PYTHON_EXTENSION_INCLUDEDIRS} )
68+ target_link_libraries (${target_name} ${ADD_PYTHON_EXTENSION_LIBRARIES} )
4769
48- # Turn off the "lib" prefix
49- set_target_properties (${target_name} PROPERTIES
50- OUTPUT_NAME "${name} "
51- PREFIX ""
52- )
70+ # Turn off the "lib" prefix
71+ set_target_properties (${target_name} PROPERTIES
72+ OUTPUT_NAME "${name} "
73+ PREFIX ""
74+ )
5375
54- install (TARGETS ${target_name} LIBRARY DESTINATION lib/${LIBPYTHON} /lib-dynload)
76+ install (TARGETS ${target_name}
77+ LIBRARY DESTINATION lib/${LIBPYTHON} /lib-dynload
78+ RUNTIME DESTINATION lib/${LIBPYTHON} /lib-dynload)
79+ endif (BUILTIN_${upper_name} )
5580endfunction (add_python_extension )
5681
5782
0 commit comments