Skip to content

Commit 8965644

Browse files
Make examples build and run on Cygwin
1 parent bd986fe commit 8965644

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cmake_install.cmake
55
.DS_Store
66
/example/example.so
77
/example/example.pyd
8+
/example/example.dll
89
*.sln
910
*.sdf
1011
*.opensdf

CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
5959
# Check for Link Time Optimization support
6060
# (GCC/Clang)
6161
CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
62-
if (HAS_LTO_FLAG)
62+
if (HAS_LTO_FLAG AND NOT CYGWIN)
6363
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
6464
endif()
6565

@@ -149,6 +149,9 @@ add_library(example SHARED
149149
${PYBIND11_EXAMPLES}
150150
)
151151

152+
# Link against the Python shared library
153+
target_link_libraries(example ${PYTHON_LIBRARY})
154+
152155
# Don't add a 'lib' prefix to the shared library
153156
set_target_properties(example PROPERTIES PREFIX "")
154157

@@ -182,9 +185,6 @@ if (WIN32)
182185

183186
# .PYD file extension on Windows
184187
set_target_properties(example PROPERTIES SUFFIX ".pyd")
185-
186-
# Link against the Python shared library
187-
target_link_libraries(example ${PYTHON_LIBRARY})
188188
elseif (UNIX)
189189
# It's quite common to have multiple copies of the same Python version
190190
# installed on one's system. E.g.: one copy from the OS and another copy
@@ -200,8 +200,13 @@ elseif (UNIX)
200200
# missing symbols, but that's perfectly fine -- they will be resolved at
201201
# import time.
202202

203-
# .SO file extension on Linux/Mac OS
204-
set_target_properties(example PROPERTIES SUFFIX ".so")
203+
# .DLL file extension on Cygwin, .SO file extension on Linux/Mac OS
204+
if (CYGWIN)
205+
set(SUFFIX ".dll")
206+
else()
207+
set(SUFFIX ".so")
208+
endif()
209+
set_target_properties(example PROPERTIES SUFFIX ${SUFFIX})
205210

206211
# Optimize for a small binary size
207212
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
@@ -213,11 +218,11 @@ elseif (UNIX)
213218
set_target_properties(example PROPERTIES MACOSX_RPATH ".")
214219
set_target_properties(example PROPERTIES LINK_FLAGS "-undefined dynamic_lookup ")
215220
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
216-
add_custom_command(TARGET example POST_BUILD COMMAND strip -u -r ${PROJECT_SOURCE_DIR}/example/example.so)
221+
add_custom_command(TARGET example POST_BUILD COMMAND strip -u -r ${PROJECT_SOURCE_DIR}/example/example${SUFFIX})
217222
endif()
218223
else()
219224
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
220-
add_custom_command(TARGET example POST_BUILD COMMAND strip ${PROJECT_SOURCE_DIR}/example/example.so)
225+
add_custom_command(TARGET example POST_BUILD COMMAND strip ${PROJECT_SOURCE_DIR}/example/example${SUFFIX})
221226
endif()
222227
endif()
223228
endif()

include/pybind11/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ struct internals {
262262
std::unordered_map<const void *, void*> registered_instances; // void * -> PyObject*
263263
std::unordered_set<std::pair<const PyObject *, const char *>, overload_hash> inactive_overload_cache;
264264
#if defined(WITH_THREAD)
265-
int tstate = 0;
265+
long tstate = 0;
266266
PyInterpreterState *istate = nullptr;
267267
#endif
268268
};

0 commit comments

Comments
 (0)