Add some missing copyright headers.
[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 # Machinery for running the external project
64 set(EXTERNAL_FFTW_VERSION 3.3.2)
65 include(ExternalProject)
66 # TODO in master branch - show this warning only on the first run
67 # by using gmx_check_if_changed_result from I21b791ab8e4f3 when
68 # that becomes available
69 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.")
70 # TODO if/when CMake fixes http://www.cmake.org/Bug/view.php?id=14330
71 # (ie. at least version > 2.8.11.2), consider reverting to using an
72 # md5sum check to avoid needing the above warning
73     ExternalProject_add(fftwBuild
74         URL "http://www.fftw.org/fftw-${EXTERNAL_FFTW_VERSION}.tar.gz"
75         CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --libdir=<INSTALL_DIR>/lib
76         ${GMX_BUILD_OWN_FFTW_SHARED_FLAG} ${GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION}
77         ${GMX_BUILD_OWN_FFTW_PREC})
78 externalproject_get_property(fftwBuild INSTALL_DIR)
79
80 string(TOUPPER "${FFTW}" UPPERFFTW)
81 string(TOLOWER "${FFTW}" LOWERFFTW)
82 string(REGEX REPLACE "fftw" "fftw3" FFTW_LIBNAME ${LOWERFFTW})
83 set(${UPPERFFTW}_LIBRARIES ${CMAKE_BINARY_PREFIX}/${INSTALL_DIR}/lib/lib${FFTW_LIBNAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
84 set(${UPPERFFTW}_INCLUDE_DIRS ${CMAKE_BINARY_PREFIX}/${INSTALL_DIR}/include PARENT_SCOPE)
85 set(${UPPERFFTW}_FOUND TRUE PARENT_SCOPE)
86 set(${UPPERFFTW}_HAVE_SIMD TRUE PARENT_SCOPE)
87
88 add_library(gmxfftw STATIC IMPORTED GLOBAL)
89 set_target_properties(gmxfftw PROPERTIES IMPORTED_LOCATION ${${UPPERFFTW}_LIBRARIES})
90 set(${UPPERFFTW}_LIBRARIES gmxfftw PARENT_SCOPE)
91 add_dependencies(gmxfftw fftwBuild)
92
93 message(STATUS "The GROMACS-managed build of FFTW 3 will configure with the following optimizations: ${GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION}")