1
1
function (add_python_extension name )
2
2
parse_arguments (ADD_PYTHON_EXTENSION
3
3
"REQUIRES;SOURCES;LIBRARIES;INCLUDEDIRS"
4
- ""
4
+ "BUILTIN "
5
5
${ARGN}
6
6
)
7
7
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
+
8
29
# Check all the things we require are found.
9
30
set (missing_deps "" )
10
- foreach (dep ${ADD_PYTHON_EXTENSION_REQUIRES} )
31
+ foreach (dep ${ADD_PYTHON_EXTENSION_REQUIRES} ENABLE_${upper_name} )
11
32
if (NOT ${dep} )
12
33
set (missing_deps "${missing_deps}${dep} " )
13
34
endif (NOT ${dep} )
@@ -23,10 +44,6 @@ function(add_python_extension name)
23
44
set (extensions_enabled "${extensions_enabled}${name} ;" CACHE INTERNAL "" FORCE )
24
45
endif (missing_deps )
25
46
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
-
30
47
# Callers to this function provide source files relative to the Modules/
31
48
# directory. We need to get absolute paths for them all.
32
49
set (absolute_sources "" )
@@ -41,17 +58,25 @@ function(add_python_extension name)
41
58
endif (${ext} STREQUAL ".S" )
42
59
endforeach (source )
43
60
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} )
47
69
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
+ )
53
75
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} )
55
80
endfunction (add_python_extension )
56
81
57
82
0 commit comments