Skip to content

WIP: CMake #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,46 @@ jobs:
script: ./tools/check_style.sh

#
# Serial Py36 / Clang36 / Release
# Serial Py36 / Clang38 / Release
#
- stage: build and test
python: "3.6"
os: linux
addons:
apt:
sources:
- llvm-toolchain-precise-3.6
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
packages:
- liblapack-dev
- libfftw3-dev
- clang-3.6
- clang-3.8
- gfortran
- libiomp-dev
env:
- NAME='clang'
- CXX_COMPILER='/usr/bin/clang++-3.6'
- C_COMPILER='/usr/bin/clang-3.6'
- CXX_COMPILER='/usr/bin/clang++-3.8'
- C_COMPILER='/usr/bin/clang-3.8'
- Fortran_COMPILER='/usr/bin/gfortran'
- BUILD_TYPE='Release'
before_script:
- python -V
- python -c 'import numpy; print(numpy.version.version)'
- cd ${TRAVIS_BUILD_DIR}
- curl https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.tar.gz --output cmake.tgz
- tar -xzvf cmake.tgz
- export CTEST_OUTPUT_ON_FAILURE=1
- ${CXX_COMPILER} --version
- ${Fortran_COMPILER} --version
- ${C_COMPILER} --version
- >
cmake -Bbuild -H.
./cmake-3.12.4-Linux-x86_64/bin/cmake -Bbuild -H.
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CXX_COMPILER}
-DCMAKE_C_COMPILER=${C_COMPILER}
-DCMAKE_Fortran_COMPILER=${Fortran_COMPILER}
-DPYTHON_EXECUTABLE=`which python`
-DINSTALL_PYMOD=ON
- cd build
- make -j 2
script: ctest -j 2 -VV
Expand Down Expand Up @@ -77,17 +81,20 @@ jobs:
- python -V
- python -c 'import numpy; print(numpy.version.version)'
- cd ${TRAVIS_BUILD_DIR}
- curl https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.tar.gz --output cmake.tgz
- tar -xzvf cmake.tgz
- export CTEST_OUTPUT_ON_FAILURE=1
- ${CXX_COMPILER} --version
- ${Fortran_COMPILER} --version
- ${C_COMPILER} --version
- >
cmake -Bbuild -H.
./cmake-3.12.4-Linux-x86_64/bin/cmake -Bbuild -H.
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CXX_COMPILER}
-DCMAKE_C_COMPILER=${C_COMPILER}
-DCMAKE_Fortran_COMPILER=${Fortran_COMPILER}
-DPYTHON_EXECUTABLE=`which python`
-DINSTALL_PYMOD=ON
- cd build
- make -j 2
script: ctest -j 2 -VV
Expand Down Expand Up @@ -120,19 +127,22 @@ jobs:
- python -V
- python -c 'import numpy; print(numpy.version.version)'
- cd ${TRAVIS_BUILD_DIR}
- curl https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.tar.gz --output cmake.tgz
- tar -xzvf cmake.tgz
- export CTEST_OUTPUT_ON_FAILURE=1
- export PATH=${TRAVIS_BUILD_DIR}:${PATH}
- ${CXX_COMPILER} --version
- ${Fortran_COMPILER} --version
- ${C_COMPILER} --version
- >
cmake -Bbuild -H.
./cmake-3.12.4-Linux-x86_64/bin/cmake -Bbuild -H.
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DENABLE_CODE_COVERAGE=ON
-DCMAKE_CXX_COMPILER=${CXX_COMPILER}
-DCMAKE_C_COMPILER=${C_COMPILER}
-DCMAKE_Fortran_COMPILER=${Fortran_COMPILER}
-DPYTHON_EXECUTABLE=`which python`
-DINSTALL_PYMOD=ON
- cd build
- cat CMakeCache.txt
- make VERBOSE=1 -j 2
Expand Down
73 changes: 36 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)

if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW) # 3.12
endif()

################ Options: Overview and Not Otherwise Mentioned ###############
#
Expand Down Expand Up @@ -42,11 +46,12 @@ set (CMAKE_CXX_STANDARD 11)
# Language bindings options
#
include(custom_color_messages)
option(ENABLE_fortran "Enables the building of Fortran bindings (needs Fortran compiler)" ON)
if(ENABLE_fortran)
option(ENABLE_Fortran "Enables the building of Fortran bindings (needs Fortran compiler)" ON)
if(ENABLE_Fortran)
enable_language(Fortran)
set(Fortran_ENABLED ON)
endif()
option(INSTALL_PYMOD "Additionally installs as independent python module in PYMOD_INSTALL_LIBDIR" OFF)

#
# Build options
Expand All @@ -66,39 +71,25 @@ option_with_flags(ENABLE_TSAN "Enables thread sanitizer" OFF
"-fsanitize=thread" "-fno-omit-frame-pointer -pie")
option_with_flags(ENABLE_UBSAN "Enables undefined behavior sanitizer" OFF
"-fsanitize=undefined" "-fno-omit-frame-pointer")
option_with_default(CMAKE_BUILD_TYPE "Build type (Release or Debug)" Release)
option_with_flags(ENABLE_XHOST "Enables processor-specific optimization" ON
"-xHost" "-march=native")
option_with_default(BUILD_FPIC "Libraries will be compiled with position independent code" ON)
option_with_print(BUILD_SHARED_LIBS "Build final library as shared, not static" ON)
option_with_default(CMAKE_INSTALL_LIBDIR "Directory to which libraries installed" lib)
option_with_default(PYMOD_INSTALL_LIBDIR "Location within CMAKE_INSTALL_LIBDIR to which python modules are installed
Must start with: / . Used to imitate python install: /python3.6/site-packages ." /)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -O0")

# FFTW
find_package(FFTW REQUIRED)
if(HAVE_FFTWF)
add_definitions(-DHAVE_FFTWF=1)
endif()
if(HAVE_FFTWD)
add_definitions(-DHAVE_FFTWD=1)
endif()
if(HAVE_FFTWL)
add_definitions(-DHAVE_FFTWL=1)
endif()

# OpenMP
if(ENABLE_OPENMP)
find_package(OpenMP)
endif()

if(OPENMP_FOUND)
add_definitions(-DHAVE_OPENMP)
if(DEFINED CMAKE_C_COMPILER_ID)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
endif()
if(DEFINED CMAKE_CXX_COMPILER_ID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
if(DEFINED CMAKE_Fortran_COMPILER_ID)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
endif()
find_package(OpenMP MODULE REQUIRED COMPONENTS CXX)
endif()

# MPI
Expand All @@ -118,13 +109,15 @@ else()
endif()
endif()

include(GNUInstallDirs)
# Find Python
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5)
find_package(PythonLibsNew 2.7 REQUIRED)
message(STATUS "${Cyan}Found Python ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}${ColourReset}: ${PYTHON_EXECUTABLE} (found version ${PYTHON_VERSION_STRING})")
set(Python_ENABLED ON) # For now, we just always assume this is on
add_subdirectory(external/pybind11)
add_subdirectory(python)
if(${INSTALL_PYMOD})
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5)
find_package(PythonLibsNew 2.7 REQUIRED)
message(STATUS "${Cyan}Found Python ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}${ColourReset}: ${PYTHON_EXECUTABLE} (found version ${PYTHON_VERSION_STRING})")
add_subdirectory(external/pybind11)
add_subdirectory(python)
endif()

# Handle different C++ libraries
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
Expand All @@ -134,17 +127,23 @@ else()
endif()

# The C++ library is linked explicitly because exception handling on macOS appears to be broken otherwise.
set(EXTERNAL_LIBRARIES ${FFTW_LIBRARIES} ${cpplib})
set(EXTERNAL_LIBRARIES fftw::fftw ${cpplib})

# Documentation
find_package(Doxygen)
find_package(Sphinx)
find_package(Latex)
if(DOXYGEN_EXECUTABLE)
if (BUILD_SPHINX)
find_package(Sphinx)
find_package(Latex)
endif()
if (BUILD_DOXYGEN)
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message (FATAL_ERROR "Doxygen is needed to build the documentation. Please install it correctly.")
endif()
if(SPHINX_EXECUTABLE)
add_subdirectory(docs)
endif()
endif()

add_subdirectory(src)


Expand Down
39 changes: 33 additions & 6 deletions cmake/FindFFTW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# FFTW_INCLUDE_DIR ... fftw include directory
#

cmake_policy(PUSH)
cmake_policy(SET CMP0074 NEW) # 3.12

#If environment variable FFTWDIR is specified, it has same effect as FFTW_ROOT
if( NOT FFTW_ROOT AND EXISTS "$ENV{FFTW_ROOT}")
set( FFTW_ROOT $ENV{FFTW_ROOT} )
Expand Down Expand Up @@ -109,29 +112,53 @@ set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAV} )

if(FFTWF_LIB)
message(STATUS "${Cyan}Found single precision FFTW: ${FFTWF_LIB}${ColourReset}")
set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTWF_LIB})
set(HAVE_FFTWF TRUE)
add_library(fftw::fftwf INTERFACE IMPORTED)
set_property(TARGET fftw::fftwf PROPERTY INTERFACE_LINK_LIBRARIES ${FFTWF_LIB})
set_property(TARGET fftw::fftwf PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${FFTW_INCLUDES})
set_property(TARGET fftw::fftwf PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_FFTWF=1)
else()
message(STATUS "${Red}Single precision FFTW not found${ColourReset}")
endif()

if(FFTW_LIB)
message(STATUS "${Cyan}Found double precision FFTW: ${FFTW_LIB}${ColourReset}")
set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LIB})
set(HAVE_FFTWD TRUE)
add_library(fftw::fftwd INTERFACE IMPORTED)
set_property(TARGET fftw::fftwd PROPERTY INTERFACE_LINK_LIBRARIES ${FFTW_LIB})
set_property(TARGET fftw::fftwd PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${FFTW_INCLUDES})
set_property(TARGET fftw::fftwd PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_FFTWD=1)
else()
message(STATUS "${Red}Double precision FFTW not found${ColourReset}")
endif()

if(FFTWL_LIB)
message(STATUS "${Cyan}Found long double precision FFTW: ${FFTWL_LIB}${ColourReset}")
set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTWL_LIB})
set(HAVE_FFTWL TRUE)
add_library(fftw::fftwl INTERFACE IMPORTED)
set_property(TARGET fftw::fftwl PROPERTY INTERFACE_LINK_LIBRARIES ${FFTWL_LIB})
set_property(TARGET fftw::fftwl PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${FFTW_INCLUDES})
set_property(TARGET fftw::fftwl PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_FFTWL=1)
else()
message(STATUS "${Red}Long double precision FFTW not found${ColourReset}")
endif()

# not the official target name and no separate F/D/L targets
# looks like this is done properly upstream, just no one distributes the pkg
# build from cmake
add_library(fftw::fftw INTERFACE IMPORTED)
if(TARGET fftw::fftwd)
set_property(TARGET fftw::fftw APPEND PROPERTY INTERFACE_LINK_LIBRARIES fftw::fftwd)
set(FFTW_LIBRARIES ${FFTW_LIBRARIES} $<TARGET_PROPERTY:fftw::fftwd,INTERFACE_LINK_LIBRARIES>)
endif()
if(TARGET fftw::fftwf)
set_property(TARGET fftw::fftw APPEND PROPERTY INTERFACE_LINK_LIBRARIES fftw::fftwf)
set(FFTW_LIBRARIES ${FFTW_LIBRARIES} $<TARGET_PROPERTY:fftw::fftwf,INTERFACE_LINK_LIBRARIES>)
endif()
if(TARGET fftw::fftwl)
set_property(TARGET fftw::fftw APPEND PROPERTY INTERFACE_LINK_LIBRARIES fftw::fftwl)
set(FFTW_LIBRARIES ${FFTW_LIBRARIES} $<TARGET_PROPERTY:fftw::fftwl,INTERFACE_LINK_LIBRARIES>)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFTW DEFAULT_MSG
FFTW_INCLUDES FFTW_LIBRARIES)
mark_as_advanced(FFTW_INCLUDES FFTW_LIBRARIES FFTW_LIB FFTWF_LIB FFTWL_LIB)
cmake_policy(POP)
63 changes: 63 additions & 0 deletions cmake/helpmeConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# helpmeConfig.cmake
# ------------------
#
# helPME cmake module.
# This module sets the following variables in your project::
#
# helpme_FOUND - true if helPME and all required components found on the system
# helpme_VERSION - helPME version in format Major.Minor.Release
# helpme_PYMOD - path to helPME python modules
#
#
# Available components::
#
# Python - Python module installed, so helpme::python is available.
#
#
# Exported targets::
#
# If helPME is found, this module defines the following :prop_tgt:`IMPORTED`
## target. Target is always shared _or_ static, so, for both, use separate, not
## overlapping, installations. ::
#
# helpme::pymod - the main Python module library.
# helpme::helpme - the main helPME C++ library with FFTW attached.
# helpme::intf_C - interface target for C linkage with main helpme library attached.
# helpme::intf_CXX -
# helpme::intf_Fortran
#
#
# Suggested usage::
#
# find_package(helpme)
# find_package(helpme 0.1 EXACT CONFIG REQUIRED COMPONENTS Python)
#
#
# The following variables can be set to guide the search for this package::
#
# helpme_DIR - CMake variable, set to directory containing this Config file
# CMAKE_PREFIX_PATH - CMake variable, set to root directory of this package
## PATH - environment variable, set to bin directory of this package
# CMAKE_DISABLE_FIND_PACKAGE_helpme - CMake variable, disables
# find_package(helpm3) when not REQUIRED, perhaps to force internal build

@PACKAGE_INIT@

set(PN helpme)

set(${PN}_PYMOD "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@@PYMOD_INSTALL_LIBDIR@")

if(@INSTALL_PYMOD@)
set(${PN}_Python_FOUND 1)
endif()

check_required_components(${PN})

#-----------------------------------------------------------------------------
# Don't include targets if this file is being picked up by another
# project which has already built this as a subproject
#-----------------------------------------------------------------------------
if(NOT TARGET ${PN}::helpme)
include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets.cmake")
endif()

30 changes: 30 additions & 0 deletions conda/_conda_vers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BEGINLICENSE
#
# This file is part of helPME, which is distributed under the BSD 3-clause license,
# as described in the LICENSE file in the top level directory of this project.
#
# Author: Andrew C. Simmonett
#
# ENDLICENSE

"""Dummy setup.py file solely for the purposes of getting an on-the-fly
computed version number into the conda recipe.

"""
import sys
from distutils.core import setup

def version_func():
import subprocess

command = 'python python/versioner.py --formatonly --format={version}'
process = subprocess.Popen(command.split(), shell=False, stdout=subprocess.PIPE)
(out, err) = process.communicate()
if sys.version_info >= (3, 0):
return out.decode('utf-8').strip()
else:
return out.strip()

setup(
version=version_func(),
)
Loading