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) ...@@ -19,6 +19,20 @@ INCLUDE(CheckFunctionExists)
INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckCSourceRuns) 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 # OS tests
IF(UNIX) IF(UNIX)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
...@@ -60,15 +74,14 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DUNIV_DEBUG -DUNIV_SYNC_DEB ...@@ -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) CHECK_FUNCTION_EXISTS(sched_getcpu HAVE_SCHED_GETCPU)
IF(NOT MSVC) IF(NOT MSVC)
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not # either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
IF(NOT CMAKE_CROSSCOMPILING)
# workaround for gcc 4.1.2 RHEL5/x86, gcc atomic ops only work under -march=i686 # 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 IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND
CMAKE_C_COMPILER_VERSION VERSION_LESS "4.1.3") CMAKE_C_COMPILER_VERSION VERSION_LESS "4.1.3")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686")
ENDIF() ENDIF()
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
" "
int main() int main()
{ {
...@@ -99,7 +112,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -99,7 +112,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_BUILTINS HAVE_IB_GCC_ATOMIC_BUILTINS
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
" "
int main() int main()
{ {
...@@ -115,7 +128,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -115,7 +128,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
"#include<stdint.h> "#include<stdint.h>
int main() int main()
{ {
...@@ -135,7 +148,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -135,7 +148,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_BUILTINS_64 HAVE_IB_GCC_ATOMIC_BUILTINS_64
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
"#include<stdint.h> "#include<stdint.h>
int main() int main()
{ {
...@@ -144,7 +157,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -144,7 +157,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_SYNC_SYNCHRONISE HAVE_IB_GCC_SYNC_SYNCHRONISE
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
"#include<stdint.h> "#include<stdint.h>
int main() int main()
{ {
...@@ -154,7 +167,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -154,7 +167,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_THREAD_FENCE HAVE_IB_GCC_ATOMIC_THREAD_FENCE
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
"#include<stdint.h> "#include<stdint.h>
int main() int main()
{ {
...@@ -166,7 +179,6 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -166,7 +179,6 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_TEST_AND_SET HAVE_IB_GCC_ATOMIC_TEST_AND_SET
) )
ENDIF()
IF(HAVE_IB_GCC_ATOMIC_BUILTINS) IF(HAVE_IB_GCC_ATOMIC_BUILTINS)
ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_BUILTINS=1) ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_BUILTINS=1)
...@@ -192,28 +204,27 @@ IF(HAVE_IB_GCC_ATOMIC_TEST_AND_SET) ...@@ -192,28 +204,27 @@ IF(HAVE_IB_GCC_ATOMIC_TEST_AND_SET)
ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_TEST_AND_SET=1) ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_TEST_AND_SET=1)
ENDIF() ENDIF()
# either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not # either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not
IF(NOT CMAKE_CROSSCOMPILING) CHECK_C_SOURCE(
CHECK_C_SOURCE_RUNS( "
" #include <pthread.h>
#include <pthread.h> #include <string.h>
#include <string.h>
int main() { int main() {
pthread_t x1; pthread_t x1;
pthread_t x2; pthread_t x2;
pthread_t x3; pthread_t x3;
memset(&x1, 0x0, sizeof(x1)); memset(&x1, 0x0, sizeof(x1));
memset(&x2, 0x0, sizeof(x2)); memset(&x2, 0x0, sizeof(x2));
memset(&x3, 0x0, sizeof(x3)); memset(&x3, 0x0, sizeof(x3));
__sync_bool_compare_and_swap(&x1, x2, x3); __sync_bool_compare_and_swap(&x1, x2, x3);
return(0);
}"
HAVE_IB_ATOMIC_PTHREAD_T_GCC)
return(0);
}"
HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ENDIF()
IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC) IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1) ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1)
ENDIF() ENDIF()
...@@ -244,7 +255,6 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") ...@@ -244,7 +255,6 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
ADD_DEFINITIONS(-DHAVE_IB_SOLARIS_ATOMICS=1) ADD_DEFINITIONS(-DHAVE_IB_SOLARIS_ATOMICS=1)
ENDIF() ENDIF()
IF(NOT CMAKE_CROSSCOMPILING)
# either define HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS or not # either define HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS or not
CHECK_C_SOURCE_COMPILES( CHECK_C_SOURCE_COMPILES(
" #include <pthread.h> " #include <pthread.h>
...@@ -283,7 +293,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") ...@@ -283,7 +293,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
return(0); return(0);
}" }"
HAVE_IB_MACHINE_BARRIER_SOLARIS) HAVE_IB_MACHINE_BARRIER_SOLARIS)
ENDIF()
IF(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS) IF(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_SOLARIS=1) ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_SOLARIS=1)
ENDIF() ENDIF()
......
...@@ -19,6 +19,20 @@ INCLUDE(CheckFunctionExists) ...@@ -19,6 +19,20 @@ INCLUDE(CheckFunctionExists)
INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckCSourceRuns) 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 # OS tests
IF(UNIX) IF(UNIX)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
...@@ -63,15 +77,14 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DUNIV_DEBUG -DUNIV_SYNC_DEB ...@@ -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) CHECK_FUNCTION_EXISTS(sched_getcpu HAVE_SCHED_GETCPU)
IF(NOT MSVC) IF(NOT MSVC)
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not # either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
IF(NOT CMAKE_CROSSCOMPILING)
# workaround for gcc 4.1.2 RHEL5/x86, gcc atomic ops only work under -march=i686 # 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 IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND
CMAKE_C_COMPILER_VERSION VERSION_LESS "4.1.3") CMAKE_C_COMPILER_VERSION VERSION_LESS "4.1.3")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686")
ENDIF() ENDIF()
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
" "
int main() int main()
{ {
...@@ -102,7 +115,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -102,7 +115,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_BUILTINS HAVE_IB_GCC_ATOMIC_BUILTINS
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
" "
int main() int main()
{ {
...@@ -118,7 +131,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -118,7 +131,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
"#include<stdint.h> "#include<stdint.h>
int main() int main()
{ {
...@@ -138,7 +151,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -138,7 +151,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_BUILTINS_64 HAVE_IB_GCC_ATOMIC_BUILTINS_64
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
"#include<stdint.h> "#include<stdint.h>
int main() int main()
{ {
...@@ -147,7 +160,7 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -147,7 +160,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_SYNC_SYNCHRONISE HAVE_IB_GCC_SYNC_SYNCHRONISE
) )
CHECK_C_SOURCE_RUNS( CHECK_C_SOURCE(
"#include<stdint.h> "#include<stdint.h>
int main() int main()
{ {
...@@ -157,7 +170,6 @@ IF(NOT CMAKE_CROSSCOMPILING) ...@@ -157,7 +170,6 @@ IF(NOT CMAKE_CROSSCOMPILING)
}" }"
HAVE_IB_GCC_ATOMIC_THREAD_FENCE HAVE_IB_GCC_ATOMIC_THREAD_FENCE
) )
ENDIF()
IF(HAVE_IB_GCC_ATOMIC_BUILTINS) IF(HAVE_IB_GCC_ATOMIC_BUILTINS)
ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_BUILTINS=1) ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_BUILTINS=1)
...@@ -180,28 +192,27 @@ IF(HAVE_IB_GCC_ATOMIC_THREAD_FENCE) ...@@ -180,28 +192,27 @@ IF(HAVE_IB_GCC_ATOMIC_THREAD_FENCE)
ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_THREAD_FENCE=1) ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_THREAD_FENCE=1)
ENDIF() ENDIF()
# either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not # either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not
IF(NOT CMAKE_CROSSCOMPILING) CHECK_C_SOURCE(
CHECK_C_SOURCE_RUNS( "
" #include <pthread.h>
#include <pthread.h> #include <string.h>
#include <string.h>
int main() { int main() {
pthread_t x1; pthread_t x1;
pthread_t x2; pthread_t x2;
pthread_t x3; pthread_t x3;
memset(&x1, 0x0, sizeof(x1)); memset(&x1, 0x0, sizeof(x1));
memset(&x2, 0x0, sizeof(x2)); memset(&x2, 0x0, sizeof(x2));
memset(&x3, 0x0, sizeof(x3)); memset(&x3, 0x0, sizeof(x3));
__sync_bool_compare_and_swap(&x1, x2, x3); __sync_bool_compare_and_swap(&x1, x2, x3);
return(0);
}"
HAVE_IB_ATOMIC_PTHREAD_T_GCC)
return(0);
}"
HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ENDIF()
IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC) IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1) ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1)
ENDIF() ENDIF()
...@@ -233,7 +244,6 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") ...@@ -233,7 +244,6 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
SET(XTRADB_OK 1) SET(XTRADB_OK 1)
ENDIF() ENDIF()
IF(NOT CMAKE_CROSSCOMPILING)
# either define HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS or not # either define HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS or not
CHECK_C_SOURCE_COMPILES( CHECK_C_SOURCE_COMPILES(
" #include <pthread.h> " #include <pthread.h>
...@@ -272,7 +282,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") ...@@ -272,7 +282,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
return(0); return(0);
}" }"
HAVE_IB_MACHINE_BARRIER_SOLARIS) HAVE_IB_MACHINE_BARRIER_SOLARIS)
ENDIF()
IF(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS) IF(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_SOLARIS=1) ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_SOLARIS=1)
ENDIF() 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