Commit 84da1547 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-8883 more cross-compiling fixes

use CHECK_C_SOURCE_COMPILES for atomic tests if cross-compiling
(continue to use CHECK_C_SOURCE_RUNS otherwise)
parent fb871338
......@@ -19,6 +19,20 @@ INCLUDE(CheckFunctionExists)
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckCSourceRuns)
IF(CMAKE_CROSSCOMPILING)
# Use CHECK_C_SOURCE_COMPILES instead of CHECK_C_SOURCE_RUNS when
# cross-compiling. Not as precise, but usually good enough.
# This only make sense for atomic tests in this file, this trick doesn't
# work in a general case.
MACRO(CHECK_C_SOURCE SOURCE VAR)
CHECK_C_SOURCE_COMPILES("${SOURCE}" "${VAR}")
ENDMACRO()
ELSE()
MACRO(CHECK_C_SOURCE SOURCE VAR)
CHECK_C_SOURCE_RUNS("${SOURCE}" "${VAR}")
ENDMACRO()
ENDIF()
# OS tests
IF(UNIX)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
......@@ -60,15 +74,14 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DUNIV_DEBUG -DUNIV_SYNC_DEB
CHECK_FUNCTION_EXISTS(sched_getcpu HAVE_SCHED_GETCPU)
IF(NOT MSVC)
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
IF(NOT CMAKE_CROSSCOMPILING)
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
# workaround for gcc 4.1.2 RHEL5/x86, gcc atomic ops only work under -march=i686
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND
CMAKE_C_COMPILER_VERSION VERSION_LESS "4.1.3")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686")
ENDIF()
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"
int main()
{
......@@ -99,7 +112,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_BUILTINS
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"
int main()
{
......@@ -115,7 +128,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"#include<stdint.h>
int main()
{
......@@ -135,7 +148,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_BUILTINS_64
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"#include<stdint.h>
int main()
{
......@@ -144,7 +157,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_SYNC_SYNCHRONISE
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"#include<stdint.h>
int main()
{
......@@ -154,7 +167,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_THREAD_FENCE
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"#include<stdint.h>
int main()
{
......@@ -166,7 +179,6 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_TEST_AND_SET
)
ENDIF()
IF(HAVE_IB_GCC_ATOMIC_BUILTINS)
ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_BUILTINS=1)
......@@ -192,14 +204,13 @@ IF(HAVE_IB_GCC_ATOMIC_TEST_AND_SET)
ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_TEST_AND_SET=1)
ENDIF()
# either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not
IF(NOT CMAKE_CROSSCOMPILING)
CHECK_C_SOURCE_RUNS(
"
#include <pthread.h>
#include <string.h>
# either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not
CHECK_C_SOURCE(
"
#include <pthread.h>
#include <string.h>
int main() {
int main() {
pthread_t x1;
pthread_t x2;
pthread_t x3;
......@@ -211,9 +222,9 @@ IF(NOT CMAKE_CROSSCOMPILING)
__sync_bool_compare_and_swap(&x1, x2, x3);
return(0);
}"
HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ENDIF()
}"
HAVE_IB_ATOMIC_PTHREAD_T_GCC)
IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1)
ENDIF()
......@@ -244,7 +255,6 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
ADD_DEFINITIONS(-DHAVE_IB_SOLARIS_ATOMICS=1)
ENDIF()
IF(NOT CMAKE_CROSSCOMPILING)
# either define HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS or not
CHECK_C_SOURCE_COMPILES(
" #include <pthread.h>
......@@ -283,7 +293,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
return(0);
}"
HAVE_IB_MACHINE_BARRIER_SOLARIS)
ENDIF()
IF(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_SOLARIS=1)
ENDIF()
......
......@@ -19,6 +19,20 @@ INCLUDE(CheckFunctionExists)
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckCSourceRuns)
IF(CMAKE_CROSSCOMPILING)
# Use CHECK_C_SOURCE_COMPILES instead of CHECK_C_SOURCE_RUNS when
# cross-compiling. Not as precise, but usually good enough.
# This only make sense for atomic tests in this file, this trick doesn't
# work in a general case.
MACRO(CHECK_C_SOURCE SOURCE VAR)
CHECK_C_SOURCE_COMPILES("${SOURCE}" "${VAR}")
ENDMACRO()
ELSE()
MACRO(CHECK_C_SOURCE SOURCE VAR)
CHECK_C_SOURCE_RUNS("${SOURCE}" "${VAR}")
ENDMACRO()
ENDIF()
# OS tests
IF(UNIX)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
......@@ -63,15 +77,14 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DUNIV_DEBUG -DUNIV_SYNC_DEB
CHECK_FUNCTION_EXISTS(sched_getcpu HAVE_SCHED_GETCPU)
IF(NOT MSVC)
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
IF(NOT CMAKE_CROSSCOMPILING)
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
# workaround for gcc 4.1.2 RHEL5/x86, gcc atomic ops only work under -march=i686
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND
CMAKE_C_COMPILER_VERSION VERSION_LESS "4.1.3")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686")
ENDIF()
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"
int main()
{
......@@ -102,7 +115,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_BUILTINS
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"
int main()
{
......@@ -118,7 +131,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"#include<stdint.h>
int main()
{
......@@ -138,7 +151,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_BUILTINS_64
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"#include<stdint.h>
int main()
{
......@@ -147,7 +160,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_SYNC_SYNCHRONISE
)
CHECK_C_SOURCE_RUNS(
CHECK_C_SOURCE(
"#include<stdint.h>
int main()
{
......@@ -157,7 +170,6 @@ IF(NOT CMAKE_CROSSCOMPILING)
}"
HAVE_IB_GCC_ATOMIC_THREAD_FENCE
)
ENDIF()
IF(HAVE_IB_GCC_ATOMIC_BUILTINS)
ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_BUILTINS=1)
......@@ -180,14 +192,13 @@ IF(HAVE_IB_GCC_ATOMIC_THREAD_FENCE)
ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_THREAD_FENCE=1)
ENDIF()
# either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not
IF(NOT CMAKE_CROSSCOMPILING)
CHECK_C_SOURCE_RUNS(
"
#include <pthread.h>
#include <string.h>
# either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not
CHECK_C_SOURCE(
"
#include <pthread.h>
#include <string.h>
int main() {
int main() {
pthread_t x1;
pthread_t x2;
pthread_t x3;
......@@ -199,9 +210,9 @@ IF(NOT CMAKE_CROSSCOMPILING)
__sync_bool_compare_and_swap(&x1, x2, x3);
return(0);
}"
HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ENDIF()
}"
HAVE_IB_ATOMIC_PTHREAD_T_GCC)
IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1)
ENDIF()
......@@ -233,7 +244,6 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
SET(XTRADB_OK 1)
ENDIF()
IF(NOT CMAKE_CROSSCOMPILING)
# either define HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS or not
CHECK_C_SOURCE_COMPILES(
" #include <pthread.h>
......@@ -272,7 +282,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
return(0);
}"
HAVE_IB_MACHINE_BARRIER_SOLARIS)
ENDIF()
IF(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_SOLARIS=1)
ENDIF()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment