b4b795223c8fb8ef4a8b97ca8d68f03fc94701cb
[alexxy/gromacs.git] / src / contrib / fftw / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 # Download and build a suitable copy of FFTW.
36 # The GROMACS team won't distribute source or binaries linked to FFTW
37 # because we are choosing to be very clear about distributing only
38 # LGPL-licensed code, to suit requirements from our funding source.
39 #
40 # Input: FFTW variable contains the FFTW component to build,
41 #        either fftw or fftwf for double or single precision
42
43 set(GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION "" CACHE INTERNAL "Optimization flags for FFTW compilation")
44 if(${CMAKE_CURRENT_BINARY_DIR} MATCHES ".*[[:space:]].*")
45     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.")
46 endif()
47
48 if(NOT GMX_DOUBLE)
49     set(GMX_BUILD_OWN_FFTW_PREC --enable-float)
50 endif()
51
52 # Always build a static lib, so it gets added to libmd and doesn't need to be installed
53 set(GMX_BUILD_OWN_FFTW_SHARED_FLAG --disable-shared --enable-static)
54 if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND BUILD_SHARED_LIBS) # FFTW doesn't use -DPIC by default
55     set(GMX_BUILD_OWN_FFTW_SHARED_FLAG ${GMX_BUILD_OWN_FFTW_SHARED_FLAG} --with-pic)
56 endif()
57
58 # Testing shows FFTW configured with --enable-avx is never better than --enable-sse2, so we do the latter always.
59 if(${GMX_CPU_ACCELERATION} MATCHES "^(SSE|AVX)")
60     set(GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION --enable-sse2 CACHE INTERNAL "Optimization flags for FFTW compilation")
61 endif()
62
63 # Allow cross-compiles
64 if (TARGET_HOST)
65     set(GMX_BUILD_OWN_FFTW_TARGET_HOST --host=${TARGET_HOST})
66 endif()
67
68 # Machinery for running the external project
69 set(EXTERNAL_FFTW_VERSION 3.3.2)
70 set(EXTERNAL_FFTW_MD5SUM 6977ee770ed68c85698c7168ffa6e178)
71 set (EXTERNAL_FFTW_BUILD_TARGET fftwBuild)
72 include(ExternalProject)
73 # TODO in master branch - show this warning only on the first run
74 # by using gmx_check_if_changed_result from I21b791ab8e4f3 when
75 # that becomes available
76 message(WARNING "The GROMACS build will download FFTW ${EXTERNAL_FFTW_VERSION} as requested, but it will not know the file it receives is correct. If you now use\nmake\n 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. Instead, you can use\nmake ${EXTERNAL_FFTW_BUILD_TARGET}\n to do just the download and build of FFTW, and then run\nmd5sum src/contrib/fftw/${EXTERNAL_FFTW_BUILD_TARGET}-prefix/src/fftw-${EXTERNAL_FFTW_VERSION}.tar.gz\nto see if it matches ${EXTERNAL_FFTW_MD5SUM}. If so, everything is OK and you should use \nmake\n to proceed with the rest of the GROMACS build. Alternatively, you could stop using GMX_BUILD_OWN_FFTW, and instead follow the GROMACS installation instructions to build FFTW yourself.")
77 # TODO if/when CMake fixes http://www.cmake.org/Bug/view.php?id=14330
78 # (ie. at least version > 2.8.11.2), consider reverting to using an
79 # md5sum check to avoid needing the above warning
80     ExternalProject_add(${EXTERNAL_FFTW_BUILD_TARGET}
81         URL "http://www.fftw.org/fftw-${EXTERNAL_FFTW_VERSION}.tar.gz"
82         CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --libdir=<INSTALL_DIR>/lib --disable-fortran
83         ${GMX_BUILD_OWN_FFTW_SHARED_FLAG} ${GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION}
84         ${GMX_BUILD_OWN_FFTW_PREC}
85         ${GMX_BUILD_OWN_FFTW_TARGET_HOST})
86 externalproject_get_property(${EXTERNAL_FFTW_BUILD_TARGET} INSTALL_DIR)
87
88 string(TOUPPER "${FFTW}" UPPERFFTW)
89 string(TOLOWER "${FFTW}" LOWERFFTW)
90 string(REGEX REPLACE "fftw" "fftw3" FFTW_LIBNAME ${LOWERFFTW})
91 set(${UPPERFFTW}_LIBRARIES ${CMAKE_BINARY_PREFIX}/${INSTALL_DIR}/lib/lib${FFTW_LIBNAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
92 set(${UPPERFFTW}_INCLUDE_DIRS ${CMAKE_BINARY_PREFIX}/${INSTALL_DIR}/include PARENT_SCOPE)
93 set(${UPPERFFTW}_FOUND TRUE PARENT_SCOPE)
94 set(${UPPERFFTW}_HAVE_SIMD TRUE PARENT_SCOPE)
95
96 add_library(gmxfftw STATIC IMPORTED GLOBAL)
97 set_target_properties(gmxfftw PROPERTIES IMPORTED_LOCATION ${${UPPERFFTW}_LIBRARIES})
98 set(${UPPERFFTW}_LIBRARIES gmxfftw PARENT_SCOPE)
99 add_dependencies(gmxfftw ${EXTERNAL_FFTW_BUILD_TARGET})
100
101 message(STATUS "The GROMACS-managed build of FFTW 3 will configure with the following optimizations: ${GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION}")