Skip to content

Commit bcc4287

Browse files
committed
CMake: don't add -pthread for Windows builds
It can generate some warnings or compilations errors. The official CMake way of picking the thread library [^1] should probably be used for non-Windows targets. [^1]: https://cmake.org/cmake/help/latest/module/FindThreads.html Signed-off-by: Steve Lhomme <robux4@ycbcr.xyz>
1 parent ef5f723 commit bcc4287

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ elseif(UNIX OR MINGW)
121121
set(OPT_DBG "-DNDEBUG") # disable assert
122122
endif()
123123

124-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_DBG} -${OPT_LV} -fomit-frame-pointer -pthread")
124+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_DBG} -${OPT_LV} -fomit-frame-pointer")
125125
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-function -Wno-pointer-sign -Wno-pointer-to-int-cast")
126+
if(NOT WIN32)
127+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
128+
endif()
126129
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lm")
127130
else()
128131
message("Unknown compiler")

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ if(NOT MSVC)
182182
set(EXTRA_CFLAGS "-DOAPV_STATIC_DEFINE")
183183
set(EXTRA_CFLAGS_PRIVATE "")
184184
endif()
185+
if(NOT WIN32)
186+
set(EXTRA_CFLAGS_PRIVATE "${EXTRA_CFLAGS_PRIVATE} -pthread")
187+
endif()
185188
configure_file(
186189
"${CMAKE_SOURCE_DIR}/pkgconfig/${LIB_NAME_BASE}.pc.in"
187190
"${CMAKE_BINARY_DIR}/${LIB_NAME_BASE}.pc" @ONLY)

0 commit comments

Comments
 (0)