mirror of https://github.com/mgba-emu/mgba.git
CMake: Clean up function detection technical debt
This commit is contained in:
parent
d996633b12
commit
de4ea9284d
109
CMakeLists.txt
109
CMakeLists.txt
|
@ -150,6 +150,7 @@ if (NOT DEFINED MANDIR)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(FindFeature)
|
include(FindFeature)
|
||||||
|
include(FindFunction)
|
||||||
|
|
||||||
# Version information
|
# Version information
|
||||||
add_custom_target(${BINARY_NAME}-version-info ALL
|
add_custom_target(${BINARY_NAME}-version-info ALL
|
||||||
|
@ -301,46 +302,33 @@ if(WII)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(CheckCCompilerFlag)
|
include(CheckCCompilerFlag)
|
||||||
include(CheckFunctionExists)
|
|
||||||
include(CheckIncludeFiles)
|
include(CheckIncludeFiles)
|
||||||
check_function_exists(strdup HAVE_STRDUP)
|
|
||||||
check_function_exists(strndup HAVE_STRNDUP)
|
set(FUNCTION_DEFINES)
|
||||||
check_function_exists(strlcpy HAVE_STRLCPY)
|
|
||||||
check_function_exists(vasprintf HAVE_VASPRINTF)
|
find_function(strdup)
|
||||||
if(NOT DEFINED PSP2)
|
find_function(strlcpy)
|
||||||
check_function_exists(localtime_r HAVE_LOCALTIME_R)
|
find_function(strndup)
|
||||||
endif()
|
find_function(vasprintf)
|
||||||
check_include_files("xlocale.h" HAVE_XLOCALE)
|
|
||||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
|
find_function(freelocale)
|
||||||
check_function_exists(snprintf_l HAVE_SNPRINTF_L)
|
find_function(newlocale)
|
||||||
|
find_function(setlocale)
|
||||||
|
find_function(snprintf_l)
|
||||||
|
find_function(uselocale)
|
||||||
|
|
||||||
if(ANDROID AND ANDROID_NDK_MAJOR GREATER 13)
|
if(ANDROID AND ANDROID_NDK_MAJOR GREATER 13)
|
||||||
set(HAVE_STRTOF_L ON)
|
set(HAVE_STRTOF_L ON)
|
||||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
# The strtof_l on Linux not actually exposed nor actually strtof_l
|
# The strtof_l on Linux not actually exposed nor actually strtof_l
|
||||||
set(HAVE_STRTOF_L OFF)
|
set(HAVE_STRTOF_L OFF)
|
||||||
else()
|
elseif(NOT DEFINED PSP2)
|
||||||
check_function_exists(strtof_l HAVE_STRTOF_L)
|
find_function(localtime_r)
|
||||||
endif()
|
find_function(strtof_l)
|
||||||
check_function_exists(newlocale HAVE_NEWLOCALE)
|
|
||||||
check_function_exists(freelocale HAVE_FREELOCALE)
|
|
||||||
check_function_exists(uselocale HAVE_USELOCALE)
|
|
||||||
check_function_exists(setlocale HAVE_SETLOCALE)
|
|
||||||
else()
|
|
||||||
if(DEFINED 3DS OR DEFINED WII OR DEFINED SWITCH)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,snprintf_l)
|
|
||||||
check_function_exists(snprintf_l HAVE_SNPRINTF_L)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,strtof_l)
|
|
||||||
check_function_exists(strtof_l HAVE_STRTOF_L)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,newlocale)
|
|
||||||
check_function_exists(newlocale HAVE_NEWLOCALE)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,freelocale)
|
|
||||||
check_function_exists(freelocale HAVE_FREELOCALE)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,uselocale)
|
|
||||||
check_function_exists(uselocale HAVE_USELOCALE)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,setlocale)
|
|
||||||
check_function_exists(setlocale HAVE_SETLOCALE)
|
|
||||||
unset(CMAKE_REQUIRED_FLAGS)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
check_include_files("xlocale.h" HAVE_XLOCALE)
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL "Generic")
|
||||||
if(NOT IS_EMBEDDED)
|
if(NOT IS_EMBEDDED)
|
||||||
set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
|
set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
@ -351,9 +339,6 @@ else()
|
||||||
set(ENABLE_EXTRA ON)
|
set(ENABLE_EXTRA ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
check_function_exists(chmod HAVE_CHMOD)
|
|
||||||
check_function_exists(umask HAVE_UMASK)
|
|
||||||
|
|
||||||
if(USE_PTHREADS)
|
if(USE_PTHREADS)
|
||||||
check_include_files("pthread.h" HAVE_PTHREAD_H)
|
check_include_files("pthread.h" HAVE_PTHREAD_H)
|
||||||
if(HAVE_PTHREAD_H)
|
if(HAVE_PTHREAD_H)
|
||||||
|
@ -363,40 +348,18 @@ if(USE_PTHREADS)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
check_function_exists(pthread_create HAVE_PTHREAD_CREATE)
|
find_function(pthread_create)
|
||||||
if(HAVE_PTHREAD_CREATE)
|
if(HAVE_PTHREAD_CREATE)
|
||||||
add_definitions(-DUSE_PTHREADS)
|
add_definitions(-DUSE_PTHREADS)
|
||||||
|
|
||||||
check_include_files("pthread_np.h" HAVE_PTHREAD_NP_H)
|
check_include_files("pthread_np.h" HAVE_PTHREAD_NP_H)
|
||||||
|
|
||||||
check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
|
find_function(pthread_setname_np)
|
||||||
check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
|
find_function(pthread_set_name_np)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(FUNCTION_DEFINES)
|
|
||||||
|
|
||||||
if(HAVE_STRDUP)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_STRDUP)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_STRNDUP)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_STRNDUP)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_STRLCPY)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_STRLCPY)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_VASPRINTF)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_VASPRINTF)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_LOCALTIME_R)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_LOCALTIME_R)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE OR APPLE)
|
if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE OR APPLE)
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_LOCALE)
|
list(APPEND FUNCTION_DEFINES HAVE_LOCALE)
|
||||||
if (HAVE_SNPRINTF_L)
|
if (HAVE_SNPRINTF_L)
|
||||||
|
@ -404,38 +367,14 @@ if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE OR APPLE)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(HAVE_SETLOCALE)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_SETLOCALE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (HAVE_STRTOF_L)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_STRTOF_L)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_XLOCALE)
|
if(HAVE_XLOCALE)
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_XLOCALE)
|
list(APPEND FUNCTION_DEFINES HAVE_XLOCALE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(HAVE_CHMOD)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_CHMOD)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_UMASK)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_UMASK)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_PTHREAD_NP_H)
|
if(HAVE_PTHREAD_NP_H)
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_NP_H)
|
list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_NP_H)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(HAVE_PTHREAD_SETNAME_NP)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_SETNAME_NP)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAVE_PTHREAD_SET_NAME_NP)
|
|
||||||
list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_SET_NAME_NP)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Feature dependencies
|
# Feature dependencies
|
||||||
set(FEATURE_DEFINES)
|
set(FEATURE_DEFINES)
|
||||||
set(FEATURE_FLAGS)
|
set(FEATURE_FLAGS)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
include(CheckFunctionExists)
|
||||||
|
function(find_function FUNCTION_NAME)
|
||||||
|
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,${FUNCTION_NAME})
|
||||||
|
string(TOUPPER ${FUNCTION_NAME} FLAG_NAME)
|
||||||
|
check_function_exists(${FUNCTION_NAME} HAVE_${FLAG_NAME})
|
||||||
|
unset(CMAKE_REQUIRED_FLAGS)
|
||||||
|
set(HAVE_${FLAG_NAME} ${HAVE_${FLAG_NAME}} PARENT_SCOPE)
|
||||||
|
if(HAVE_${FLAG_NAME})
|
||||||
|
list(APPEND FUNCTION_DEFINES HAVE_${FLAG_NAME})
|
||||||
|
set(FUNCTION_DEFINES "${FUNCTION_DEFINES}" PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
Loading…
Reference in New Issue