Skip to content

Commit

Permalink
cmake: check platform early
Browse files Browse the repository at this point in the history
  • Loading branch information
kmilos authored and TurboGit committed Aug 24, 2022
1 parent 287c111 commit 7874783
Showing 1 changed file with 34 additions and 48 deletions.
82 changes: 34 additions & 48 deletions ConfigureChecks.cmake
@@ -1,24 +1,35 @@
include(CheckCSourceCompiles)
include(TestBigEndian)
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CheckStructHasMember)

check_include_file(cpuid.h HAVE_CPUID_H)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR})

if (HAVE_CPUID_H)
check_symbol_exists(__get_cpuid "cpuid.h" HAVE___GET_CPUID)
check_c_source_compiles(
"#include <stdio.h>
int main() {
#include \"src/is_supported_platform.h\"
}"
IS_SUPPORTED_PLATFORM)
if(NOT IS_SUPPORTED_PLATFORM)
message(FATAL_ERROR "The target platform is not supported!")
endif()

check_include_file(execinfo.h HAVE_EXECINFO_H)
set(CMAKE_REQUIRED_INCLUDES)

if (OpenMP_FOUND)
check_include_file(cpuid.h HAVE_CPUID_H)
if(HAVE_CPUID_H)
check_symbol_exists(__get_cpuid "cpuid.h" HAVE___GET_CPUID)
endif()

check_include_file(execinfo.h HAVE_EXECINFO_H)

set(CMAKE_REQUIRED_FLAGS ${OpenMP_C_FLAGS})
set(CMAKE_REQUIRED_LIBRARIES ${OpenMP_C_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${OpenMP_C_INCLUDE_DIRS})
check_c_source_compiles("
#include <omp.h>
if(OpenMP_FOUND)
set(CMAKE_REQUIRED_FLAGS ${OpenMP_C_FLAGS})
set(CMAKE_REQUIRED_LIBRARIES ${OpenMP_C_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${OpenMP_C_INCLUDE_DIRS})
check_c_source_compiles(
"#include <omp.h>
static void sink(const int x, int a[])
{
Expand All @@ -36,11 +47,12 @@ int main(void)
sink(x, a);
return 0;
}" HAVE_OMP_FIRSTPRIVATE_WITH_CONST)
}"
HAVE_OMP_FIRSTPRIVATE_WITH_CONST)

set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES)
endif()

#
Expand All @@ -49,40 +61,14 @@ endif()
set(CMAKE_REQUIRED_FLAGS ${THREADS_PREFER_PTHREAD_FLAG})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})

check_struct_has_member("struct __pthread_rwlock_arch_t"
"__readers"
"pthread.h"
HAVE_THREAD_RWLOCK_ARCH_T_READERS
LANGUAGE C)
check_struct_has_member(
"struct __pthread_rwlock_arch_t" "__readers" "pthread.h"
HAVE_THREAD_RWLOCK_ARCH_T_READERS LANGUAGE C)

check_struct_has_member("struct __pthread_rwlock_arch_t"
"__nr_readers"
"pthread.h"
HAVE_THREAD_RWLOCK_ARCH_T_NR_READERS
LANGUAGE C)
check_struct_has_member(
"struct __pthread_rwlock_arch_t" "__nr_readers" "pthread.h"
HAVE_THREAD_RWLOCK_ARCH_T_NR_READERS LANGUAGE C)

unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)

set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR})

check_c_source_compiles("#include <stdio.h>
int main() {
#include \"src/is_supported_platform.h\"
}" IS_SUPPORTED_PLATFORM)
if (IS_SUPPORTED_PLATFORM)
message(STATUS "Is the target platform supported: ${IS_SUPPORTED_PLATFORM}")
else()
message(FATAL_ERROR "The target platform is not supported!")
endif()

set(CMAKE_REQUIRED_INCLUDES)

test_big_endian(BIGENDIAN)
if(${BIGENDIAN})
# we do not really want those.
# besides, no one probably tried darktable on such systems
message(FATAL_ERROR "Found big endian system. Bad.")
else()
message(STATUS "Found little endian system. Good.")
endif(${BIGENDIAN})
unset(CMAKE_REQUIRED_INCLUDES)

0 comments on commit 7874783

Please sign in to comment.