Skip to content

Commit 18d4975

Browse files
committed
Mingw32 support, and add cmake options for disabling extensions or making them builtin
1 parent 1d82f67 commit 18d4975

File tree

10 files changed

+301
-156
lines changed

10 files changed

+301
-156
lines changed

CMakeLists.txt

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ find_library(GDBM_COMPAT_LIBRARY gdbm_compat)
3030
find_path(READLINE_INCLUDE_PATH readline/readline.h)
3131
find_library(READLINE_LIBRARY readline)
3232

33+
find_path(SQLITE3_INCLUDE_PATH sqlite3.h)
34+
find_library(SQLITE3_LIBRARY sqlite3)
35+
3336
# Options
3437
option(ENABLE_SHARED "Build a shared libpython library" OFF)
3538
option(ENABLE_STATIC "Build a static libpython library" ON)
@@ -41,14 +44,19 @@ endif (NOT ENABLE_SHARED AND NOT ENABLE_STATIC)
4144
include_directories(${CMAKE_SOURCE_DIR})
4245
include_directories(${CMAKE_SOURCE_DIR}/cmake)
4346
include_directories(${CMAKE_SOURCE_DIR}/Include)
47+
include_directories(${CMAKE_SOURCE_DIR}/Python)
4448

45-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes")
49+
if(UNIX)
50+
include_directories(${CMAKE_SOURCE_DIR}/cmake/config-unix)
51+
elseif(WIN32)
52+
include_directories(${CMAKE_SOURCE_DIR}/PC)
53+
endif(UNIX)
4654

47-
add_subdirectory(cmake/pgen)
48-
add_subdirectory(cmake/libpython)
49-
add_subdirectory(cmake/python)
50-
add_subdirectory(cmake/include)
51-
add_subdirectory(cmake/lib)
55+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes")
56+
57+
if(NOT WIN32)
58+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
59+
endif(NOT WIN32)
5260

5361
# Install some configuration information
5462
configure_file(cmake/makefile-variables.in
@@ -59,7 +67,25 @@ install(FILES ${CMAKE_BINARY_DIR}/makefile-variables
5967
install(FILES cmake/pyconfig.h
6068
DESTINATION include/${LIBPYTHON}/)
6169

70+
# Useful additional variables that extensions can use.
71+
if(UNIX AND NOT APPLE)
72+
set(LINUX ON)
73+
else(UNIX AND NOT APPLE)
74+
set(LINUX OFF)
75+
endif(UNIX AND NOT APPLE)
76+
77+
# Add extension modules
78+
set(builtin_extensions "" CACHE INTERNAL "" FORCE)
79+
set(builtin_source "" CACHE INTERNAL "" FORCE)
6280
set(extensions_enabled "" CACHE INTERNAL "" FORCE)
6381
set(extensions_disabled "" CACHE INTERNAL "" FORCE)
6482
add_subdirectory(cmake/extensions)
83+
84+
# Add the other subdirectories
85+
add_subdirectory(cmake/pgen)
86+
add_subdirectory(cmake/libpython)
87+
add_subdirectory(cmake/python)
88+
add_subdirectory(cmake/include)
89+
add_subdirectory(cmake/lib)
90+
6591
show_extension_summary()

Modules/config.c

Lines changed: 0 additions & 90 deletions
This file was deleted.

cmake/Extensions.cmake

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
function(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})
5580
endfunction(add_python_extension)
5681

5782

File renamed without changes.

cmake/config.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "Python.h"
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
// Init functions common to all platforms
8+
extern void init_ast(void);
9+
extern void init_codecs(void);
10+
extern void initerrno(void);
11+
extern void initgc(void);
12+
extern void initimp(void);
13+
extern void initsignal(void);
14+
extern void init_sre(void);
15+
extern void init_symtable(void);
16+
extern void initthread(void);
17+
extern void init_weakref(void);
18+
extern void initxxsubtype(void);
19+
extern void initzipimport(void);
20+
extern void PyMarshal_Init(void);
21+
extern void _PyWarnings_Init(void);
22+
23+
// Init functions for platform-specific extensions
24+
#include "platform-config-inits.c"
25+
26+
27+
struct _inittab _PyImport_Inittab[] = {
28+
// Entries common to all platforms
29+
{"_ast", init_ast},
30+
{"__builtin__", NULL},
31+
{"_codecs", init_codecs},
32+
{"errno", initerrno},
33+
{"exceptions", NULL},
34+
{"gc", initgc},
35+
{"imp", initimp},
36+
{"__main__", NULL},
37+
{"marshal", PyMarshal_Init},
38+
{"signal", initsignal},
39+
{"_sre", init_sre},
40+
{"_symtable", init_symtable},
41+
{"sys", NULL},
42+
{"thread", initthread},
43+
{"_warnings", _PyWarnings_Init},
44+
{"_weakref", init_weakref},
45+
{"xxsubtype", initxxsubtype},
46+
{"zipimport", initzipimport},
47+
48+
// Entries for platform-specific extensions
49+
#include "platform-config-entries.c"
50+
51+
// Sentinel
52+
{0, 0}
53+
};
54+
55+
56+
#ifdef __cplusplus
57+
}
58+
#endif

0 commit comments

Comments
 (0)