Drop md5sum check for GMX_BUILD_OWN_FFTW
[alexxy/gromacs.git] / src / contrib / fftw / CMakeLists.txt
1 # Download and build a suitable copy of FFTW.
2 # The GROMACS team won't distribute source or binaries linked to FFTW
3 # because we are choosing to be very clear about distributing only
4 # LGPL-licensed code, to suit requirements from our funding source.
5 #
6 # Input: FFTW variable contains the FFTW component to build,
7 #        either fftw or fftwf for double or single precision
8
9 set(GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION "" CACHE INTERNAL "Optimization flags for FFTW compilation")
10 if(${CMAKE_CURRENT_BINARY_DIR} MATCHES ".*[[:space:]].*")
11     message(FATAL_ERROR "An internal limitation of FFTW means GROMACS cannot build FFTW in a directory with whitespace in its name. Either use a system FFTW, build it yourself, or build GROMACS in a different location.")
12 endif()
13
14 if(NOT GMX_DOUBLE)
15     set(GMX_BUILD_OWN_FFTW_PREC --enable-float)
16 endif()
17
18 # Always build a static lib, so it gets added to libmd and doesn't need to be installed
19 set(GMX_BUILD_OWN_FFTW_SHARED_FLAG --disable-shared --enable-static)
20 if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND BUILD_SHARED_LIBS) # FFTW doesn't use -DPIC by default
21     set(GMX_BUILD_OWN_FFTW_SHARED_FLAG ${GMX_BUILD_OWN_FFTW_SHARED_FLAG} --with-pic)
22 endif()
23
24 # Testing shows FFTW configured with --enable-avx is never better than --enable-sse2, so we do the latter always.
25 if(${GMX_CPU_ACCELERATION} MATCHES "^(SSE|AVX)")
26     set(GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION --enable-sse2 CACHE INTERNAL "Optimization flags for FFTW compilation")
27 endif()
28
29 # Machinery for running the external project
30 set(EXTERNAL_FFTW_VERSION 3.3.2)
31 include(ExternalProject)
32 # TODO in master branch - show this warning only on the first run
33 # by using gmx_check_if_changed_result from I21b791ab8e4f3 when
34 # that becomes available
35 message(WARNING "The GROMACS build will download FFTW ${EXTERNAL_FFTW_VERSION} as requested, but it will not know the file it receives is correct. GROMACS will build and link to FFTW anyway, but there is a possible security risk if you execute a GROMACS tool that calls this library. You can use\nmake gmxfftw\n to do the download and build, and then run\nmd5sum src/contrib/fftw/gmxfftw-prefix/src/fftw-3.3.2.tar.gz\nto see if it matches 6977ee770ed68c85698c7168ffa6e178. If so, everything is OK and you should proceed with the rest of the GROMACS build. Alternatively, you can follow the GROMACS installation instructions to build FFTW yourself.")
36 # TODO if/when CMake fixes http://www.cmake.org/Bug/view.php?id=14330
37 # (ie. at least version > 2.8.11.2), consider reverting to using an
38 # md5sum check to avoid needing the above warning
39     ExternalProject_add(gmxfftw
40         URL "http://www.fftw.org/fftw-${EXTERNAL_FFTW_VERSION}.tar.gz"
41         CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
42         ${GMX_BUILD_OWN_FFTW_SHARED_FLAG} ${GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION}
43         ${GMX_BUILD_OWN_FFTW_PREC})
44 externalproject_get_property(gmxfftw INSTALL_DIR)
45 # The dependency that triggers building the gmxfftw target gets made where libmd is constructed
46
47 string(TOUPPER "${FFTW}" UPPERFFTW)
48 string(TOLOWER "${FFTW}" LOWERFFTW)
49 string(REGEX REPLACE "fftw" "fftw3" FFTW_LIBNAME ${LOWERFFTW})
50 set(${UPPERFFTW}_LIBRARIES ${CMAKE_BINARY_PREFIX}/${INSTALL_DIR}/lib/lib${FFTW_LIBNAME}${CMAKE_STATIC_LIBRARY_SUFFIX} PARENT_SCOPE)
51 set(${UPPERFFTW}_INCLUDE_DIRS ${CMAKE_BINARY_PREFIX}/${INSTALL_DIR}/include PARENT_SCOPE)
52 set(${UPPERFFTW}_FOUND TRUE PARENT_SCOPE)
53 set(${UPPERFFTW}_HAVE_SIMD TRUE PARENT_SCOPE)
54
55 message(STATUS "The GROMACS-managed build of FFTW 3 will configure with the following optimizations: ${GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION}")