Skip to content

Commit

Permalink
Fix mingw-w64:llvm-mingw error: unknown type name 'pthread_t' (#653)
Browse files Browse the repository at this point in the history
* Include <pthread.h> in astc_encode.cpp for non Windows and WIN32_HAS_PTHREADS.
* Fix test for setting WIN32_HAS_PTHREADS to set only when pthreads found.
* Fix duplicate definition warnings for KTX_API when building static library for Windows.

Fixes #651.
  • Loading branch information
FuXiii authored Dec 3, 2022
1 parent 92bf412 commit 7d57639
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ macro(commom_lib_settings lib write)
)

if( LIB_TYPE STREQUAL STATIC )
# KHRONOS_STATIC overrides the value of KTX_API set below.
target_compile_definitions(${lib} PUBLIC KHRONOS_STATIC)
endif()

Expand All @@ -340,9 +339,8 @@ macro(commom_lib_settings lib write)
target_compile_definitions(
${lib}
PRIVATE
# KHRONOS_STATIC defined earlier for the static library overrides
# so no need for a generator expression to conditionally set this.
KTX_API=__declspec\(dllexport\)
# Only set dllexport when building a shared library.
$<$<STREQUAL:${LIB_TYPE},SHARED>:KTX_API=__declspec\(dllexport\)>
PUBLIC # only for basisu_c_binding.
BASISU_NO_ITERATOR_DEBUG_LEVEL
)
Expand Down Expand Up @@ -405,7 +403,7 @@ macro(commom_lib_settings lib write)
if(MINGW)
# Check if the Threads package is provided; if using Mingw it MIGHT be
find_package(Threads)
if(Threads_FOUND)
if(Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
target_compile_definitions(ktx PRIVATE WIN32_HAS_PTHREADS)
target_link_libraries(ktx PRIVATE Threads::Threads)
endif()
Expand Down
6 changes: 3 additions & 3 deletions lib/astc_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@

#include "astc-encoder/Source/astcenc.h"

#if !defined(_WIN32) || defined(WIN32_HAS_PTHREADS)
#include <pthread.h>
#else
// Provide pthreads support on windows
#if defined(_WIN32) && !defined(WIN32_HAS_PTHREADS)

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

Expand All @@ -60,7 +61,6 @@ pthread_join(pthread_t thread, void** value) {
WaitForSingleObject(thread, INFINITE);
return 0;
}

#endif

static astcenc_image*
Expand Down

0 comments on commit 7d57639

Please sign in to comment.