From 92db9b223c8d7110348dc8e9f268849e6eb683c5 Mon Sep 17 00:00:00 2001 From: John Regan Date: Tue, 16 Mar 2021 14:17:08 -0400 Subject: [PATCH] Allow building libmgba with threads disabled Unsure if this should be the default for the LIBMGBA_ONLY option, so it still defaults to wanting threads. Also allows building a shared library with the LIBMGBA_ONLY target, by only setting it if not already defined. --- CMakeLists.txt | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b3ce5fded54..f8bcc3395ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,8 @@ if(NOT LIBMGBA_ONLY) set(BUILD_GLES3 OFF CACHE BOOL "Build with OpenGL|ES 3") set(USE_EPOXY ON CACHE STRING "Build with libepoxy") set(DISABLE_DEPS OFF CACHE BOOL "Build without dependencies") + set(DISABLE_THREADS OFF CACHE BOOL "Build without threads") + mark_as_advanced(DISABLE_THREADS) set(DISTBUILD OFF CACHE BOOL "Build distribution packages") if(WIN32) set(WIN32_UNIX_PATHS OFF CACHE BOOL "Use Unix-like paths") @@ -82,8 +84,15 @@ if(NOT LIBMGBA_ONLY) else() set(DISABLE_FRONTENDS ON) set(DISABLE_DEPS ON) - set(BUILD_STATIC ON) - set(BUILD_SHARED OFF) + if(NOT DEFINED DISABLE_THREADS) + set(DISABLE_THREADS OFF) + endif() + if(NOT DEFINED BUILD_STATIC) + set(BUILD_STATIC ON) + endif() + if(NOT DEFINED BUILD_SHARED) + set(BUILD_SHARED OFF) + endif() if(NOT DEFINED M_CORE_GBA) set(M_CORE_GBA ON) endif() @@ -92,6 +101,10 @@ else() endif() endif() +if(DISABLE_THREADS) + add_definitions(-DDISABLE_THREADING) +endif() + file(GLOB THIRD_PARTY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/inih/*.c) set(CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-mem.c ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fifo.c) set(VFS_SRC) @@ -200,7 +213,9 @@ if(WIN32) file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/*.c) source_group("Windows-specific code" FILES ${OS_SRC}) elseif(UNIX) - set(USE_PTHREADS ON) + if(NOT DISABLE_THREADS) + set(USE_PTHREADS ON) + endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") add_definitions(-D_GNU_SOURCE)