From 7dc675c6a3f456f832f263483574334bc6bd67fa Mon Sep 17 00:00:00 2001 From: Erik Lindahl Date: Fri, 30 Aug 2019 21:39:21 +0200 Subject: [PATCH] Fix CPU detection and SIMD on modern Mac/cmake combos With recent versions of cmake on Mac, the CPU detection program failed to compile since it was very fragile (buggy) with respect to how compiler flags were defined - and that in turn will mean losing all SIMD support. This will fix the build, and it also adds a more vocal warning if the CPU detection code cannot be compiled at all. Change-Id: Idcdc8b59a4252b3faf8572311d2ca63a4d2a1bc0 --- cmake/gmxDetectCpu.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmake/gmxDetectCpu.cmake b/cmake/gmxDetectCpu.cmake index d5a8f12a2c..ed5fc17c39 100644 --- a/cmake/gmxDetectCpu.cmake +++ b/cmake/gmxDetectCpu.cmake @@ -1,7 +1,7 @@ # # This file is part of the GROMACS molecular simulation package. # -# Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by +# Copyright (c) 2012,2013,2014,2015,2016,2017,2019, by the GROMACS development team, led by # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, # and including many others, as listed in the AUTHORS file in the # top-level source directory and at http://www.gromacs.org. @@ -78,13 +78,13 @@ function(gmx_run_cpu_detection TYPE) # for x86 we need inline assembly to use cpuid gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM) if(GMX_X86_GCC_INLINE_ASM) - set(GCC_INLINE_ASM_DEFINE "-DGMX_X86_GCC_INLINE_ASM=1") + set(GCC_INLINE_ASM_DEFINE -DGMX_X86_GCC_INLINE_ASM=1) else() - set(GCC_INLINE_ASM_DEFINE "-DGMX_X86_GCC_INLINE_ASM=0") + set(GCC_INLINE_ASM_DEFINE -DGMX_X86_GCC_INLINE_ASM=0) endif() - set(_compile_definitions "${GCC_INLINE_ASM_DEFINE} -I${PROJECT_SOURCE_DIR}/src -DGMX_CPUINFO_STANDALONE ${GMX_STDLIB_CXX_FLAGS} -DGMX_TARGET_X86=${GMX_TARGET_X86_VALUE}") - set(LINK_LIBRARIES "${GMX_STDLIB_LIBRARIES}") + set(_compile_definitions ${GCC_INLINE_ASM_DEFINE};-I${PROJECT_SOURCE_DIR}/src;-DGMX_CPUINFO_STANDALONE=1;-DGMX_TARGET_X86=${GMX_TARGET_X86_VALUE}) + set(LINK_LIBRARIES ${GMX_STDLIB_LIBRARIES}) try_compile(CPU_DETECTION_COMPILED "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp" @@ -93,7 +93,11 @@ function(gmx_run_cpu_detection TYPE) OUTPUT_VARIABLE CPU_DETECTION_COMPILED_OUTPUT COPY_FILE ${CPU_DETECTION_BINARY}) if(NOT CPU_DETECTION_COMPILED AND NOT RUN_CPU_DETECTION_COMPILATION_QUIETLY) - message(STATUS "Did not detect build CPU ${LOWERTYPE} - detection program did not compile") + if(GMX_TARGET_X86) + message(WARNING "CPU detection program did not compile on x86 host - this should never happen. It is VERY bad for performance, since you will lose all SIMD support. Please file a bug report.") + else() + message(WARNING "Did not detect build CPU ${LOWERTYPE} - detection program did not compile. Please file a bug report if this is a common platform.") + endif() endif() set(RUN_CPU_DETECTION_COMPILATION_QUIETLY TRUE CACHE INTERNAL "Keep quiet on any future compilation attempts") endif() -- 2.11.4.GIT