Skip to content

Commit dcc303b

Browse files
committed
CMake !@#$%^&*()*&^5 sh*te fixes and tweaks:
- https://gitlab.kitware.com/cmake/cmake/-/issues/21476 Work-around for that does not fly without: https://stackoverflow.com/questions/11801186/cmake-unable-to-determine-linker-language-with-c/11802004#answer-11802004 as you'ld otherwise end up with missing default libs for the linker in MSVC in CXX/C++ mode. And, NO, https://stackoverflow.com/questions/56462415/cmake-error-cannot-determine-link-language-for-target (`set_target_properties($target PROPERTIES LINKER_LANGUAGE CXX)`) does NOT suffice!
1 parent cbaff81 commit dcc303b

File tree

6 files changed

+135
-27
lines changed

6 files changed

+135
-27
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ $RECYCLE.BIN/
232232
*.egg-info
233233
dist/
234234
build/
235+
b/
235236
eggs/
236237
parts/
237238
var/
@@ -272,4 +273,4 @@ pip-log.txt
272273
/windows/VS2019/Release-*/
273274

274275
.idea
275-
cmake-build*
276+
cmake-build*

CMakeLists.txt

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ message(STATUS "Generator ......... ${CMAKE_GENERATOR}")
1313
message(STATUS "Build Type ........ ${CMAKE_BUILD_TYPE}")
1414
message(STATUS "Version ........... ${PTHREADS4W_VERSION}")
1515

16-
project(pthreads4w VERSION ${PTHREADS4W_VERSION} LANGUAGES C)
16+
project(pthreads4w VERSION ${PTHREADS4W_VERSION} LANGUAGES C CXX)
1717

1818
set(PTW32_VER ${PROJECT_VERSION_MAJOR}${EXTRAVERSION})
1919
if(NOT CMAKE_DEBUG_POSTFIX)
@@ -91,9 +91,9 @@ if(MSVC)
9191
# (Note: If you are using Microsoft VC++6.0, the library needs to be built
9292
# with /EHa instead of /EHs or else cancellation won't work properly.)
9393
if(MSVC_VERSION EQUAL 1200)
94-
set(VCEFLAGS "/EHa /TP ")
94+
set(VCEFLAGS "/EHa ")
9595
else()
96-
set(VCEFLAGS "/EHs /TP ")
96+
set(VCEFLAGS "/EHs ")
9797
endif()
9898

9999
add_definitions(-DHAVE_CONFIG_H -DPTW32_RC_MSC)
@@ -113,10 +113,15 @@ endif()
113113

114114
macro(shared_lib type def)
115115
set(targ pthread${type}${PTW32_VER})
116-
add_library(${targ} SHARED pthread.c ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
116+
if(${type} STREQUAL "VCE" OR ${type} STREQUAL "VSE")
117+
add_library(${targ} SHARED pthread-EH.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
118+
#set_target_properties(${targ} PROPERTIES LINKER_LANGUAGE CXX)
119+
else()
120+
add_library(${targ} SHARED pthread-JMP.c ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
121+
endif()
117122
message(STATUS ${targ})
118123
target_compile_definitions(${targ} PUBLIC "-D${def}")
119-
if(${type} STREQUAL "VCE")
124+
if(${type} STREQUAL "VCE" OR ${type} STREQUAL "VSE")
120125
set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS})
121126
endif()
122127
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
@@ -130,10 +135,15 @@ endmacro()
130135

131136
macro(static_lib type def)
132137
set(targ libpthread${type}${PTW32_VER})
133-
add_library(${targ} STATIC pthread.c)
138+
if(${type} STREQUAL "VCE" OR ${type} STREQUAL "VSE")
139+
add_library(${targ} STATIC pthread-EH.cpp)
140+
#set_target_properties(${targ} PROPERTIES LINKER_LANGUAGE CXX)
141+
else()
142+
add_library(${targ} STATIC pthread-JMP.c)
143+
endif()
134144
message(STATUS ${targ})
135145
target_compile_definitions(${targ} PUBLIC "-D${def}" -DPTW32_STATIC_LIB)
136-
if(${type} STREQUAL "VCE")
146+
if(${type} STREQUAL "VCE" OR ${type} STREQUAL "VSE")
137147
set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS})
138148
endif()
139149
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
@@ -143,24 +153,13 @@ macro(static_lib type def)
143153
endif()
144154
endmacro()
145155

156+
shared_lib ( VCE PTW32_CLEANUP_CXX )
157+
shared_lib ( VSE PTW32_CLEANUP_SEH )
158+
shared_lib ( VC PTW32_CLEANUP_C )
146159

147-
option(PTHREAD_BUILD_SHARED_LIBRARY "Build shared library" OFF)
148-
set(_build_shared_library ${PTHREAD_BUILD_SHARED_LIBRARY})
149-
set(PTHREAD_BUILD_TYPE "VC" CACHE STRING "VC/VSE/VCE")
150-
151-
if(PTHREAD_BUILD_TYPE STREQUAL "VC")
152-
set(def_ PTW32_CLEANUP_C)
153-
elseif(PTHREAD_BUILD_TYPE STREQUAL "VSE" OR PTHREAD_BUILD_TYPE STREQUAL "VCE")
154-
set(def_ PTW32_CLEANUP_C)
155-
else()
156-
message(FATAL_ERROR "Unsupported pthread type ${PTHREAD_BUILD_TYPE}")
157-
endif()
158-
159-
if(_build_shared_library)
160-
shared_lib (${PTHREAD_BUILD_TYPE} PTW32_CLEANUP_C)
161-
else()
162-
static_lib (${PTHREAD_BUILD_TYPE} PTW32_CLEANUP_C)
163-
endif()
160+
static_lib ( VCE PTW32_CLEANUP_CXX )
161+
static_lib ( VSE PTW32_CLEANUP_SEH )
162+
static_lib ( VC PTW32_CLEANUP_C )
164163

165164
#################################
166165
# Install #

pthread-EH.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* pthread-EH.cpp
3+
*
4+
* Description:
5+
* Work-around for https://gitlab.kitware.com/cmake/cmake/-/issues/21476 and
6+
* other rigs where 'compile C source file as C++' enforcement is a problem.
7+
*
8+
* Quoting the CMake issue (remark by Kevin Puetz, 2020):
9+
*
10+
* One answer that just came to mind: create a pthread.cxx, that just
11+
* consists of #include "pthread.c", and let the preprocessor paste the
12+
* code in. Then CMake just sees two files and it's all normal. [...]
13+
*
14+
* See also https://discourse.cmake.org/t/compiling-c-as-c-in-cmake-3-18/2172.
15+
*
16+
* --------------------------------------------------------------------------
17+
*
18+
* pthreads-win32 - POSIX Threads Library for Win32
19+
* Copyright(C) 1998 John E. Bossom
20+
* Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors
21+
*
22+
* Homepage1: http://sourceware.org/pthreads-win32/
23+
* Homepage2: http://sourceforge.net/projects/pthreads4w/
24+
*
25+
* The current list of contributors is contained
26+
* in the file CONTRIBUTORS included with the source
27+
* code distribution. The list can also be seen at the
28+
* following World Wide Web location:
29+
* http://sources.redhat.com/pthreads-win32/contributors.html
30+
*
31+
* This library is free software; you can redistribute it and/or
32+
* modify it under the terms of the GNU Lesser General Public
33+
* License as published by the Free Software Foundation; either
34+
* version 2 of the License, or (at your option) any later version.
35+
*
36+
* This library is distributed in the hope that it will be useful,
37+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
38+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39+
* Lesser General Public License for more details.
40+
*
41+
* You should have received a copy of the GNU Lesser General Public
42+
* License along with this library in the file COPYING.LIB;
43+
* if not, write to the Free Software Foundation, Inc.,
44+
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
45+
*
46+
* --------------------------------------------------------------------------
47+
*/
48+
49+
#ifdef HAVE_CONFIG_H
50+
# include "config.h"
51+
#endif
52+
53+
#define __PTHREAD_JUMBO_BUILD__ 1
54+
#include "pthread.c"

pthread-JMP.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* pthread-JMP.c
3+
*
4+
* Description:
5+
* Addition to the work-around for https://gitlab.kitware.com/cmake/cmake/-/issues/21476 and
6+
* other rigs where 'compile C source file as C++' enforcement is a problem.
7+
*
8+
* This is the master 'jumbo' C loader file, which will only expand `pthread.c`
9+
* contents when those DO NOT require C++ compiler mode.
10+
*
11+
* --------------------------------------------------------------------------
12+
*
13+
* pthreads-win32 - POSIX Threads Library for Win32
14+
* Copyright(C) 1998 John E. Bossom
15+
* Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors
16+
*
17+
* Homepage1: http://sourceware.org/pthreads-win32/
18+
* Homepage2: http://sourceforge.net/projects/pthreads4w/
19+
*
20+
* The current list of contributors is contained
21+
* in the file CONTRIBUTORS included with the source
22+
* code distribution. The list can also be seen at the
23+
* following World Wide Web location:
24+
* http://sources.redhat.com/pthreads-win32/contributors.html
25+
*
26+
* This library is free software; you can redistribute it and/or
27+
* modify it under the terms of the GNU Lesser General Public
28+
* License as published by the Free Software Foundation; either
29+
* version 2 of the License, or (at your option) any later version.
30+
*
31+
* This library is distributed in the hope that it will be useful,
32+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34+
* Lesser General Public License for more details.
35+
*
36+
* You should have received a copy of the GNU Lesser General Public
37+
* License along with this library in the file COPYING.LIB;
38+
* if not, write to the Free Software Foundation, Inc.,
39+
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
40+
*
41+
* --------------------------------------------------------------------------
42+
*/
43+
44+
#ifdef HAVE_CONFIG_H
45+
# include "config.h"
46+
#endif
47+
48+
#define __PTHREAD_JUMBO_BUILD__ 1
49+
#include "pthread.c"

pthread.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* pthread.c
33
*
44
* Description:
5-
* This translation unit agregates pthreads-win32 translation units.
5+
* This translation unit aggregates pthreads-win32 translation units.
66
* It is used for inline optimisation of the library,
77
* maximising for speed at the expense of size.
88
*
@@ -39,6 +39,9 @@
3939
* --------------------------------------------------------------------------
4040
*/
4141

42+
// See pthread-EH.cpp and pthread-JMP.c: prevent double definitions in monolithic (automated) builds
43+
#ifdef __PTHREAD_JUMBO_BUILD__
44+
4245
#ifdef HAVE_CONFIG_H
4346
# include "config.h"
4447
#endif
@@ -194,3 +197,5 @@
194197
#include "pthread_setname_np.c"
195198
#include "pthread_setspecific.c"
196199
#include "pthread_getspecific.c"
200+
201+
#endif

pthread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#else
8787
# define PTW32_CLEANUP_C
8888
#endif
89-
#endif
89+
#endif // SEH || CXX || C
9090

9191
#if defined( PTW32_CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined (PTW32_RC_MSC))
9292
#error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler.

0 commit comments

Comments
 (0)