Skip to content

Commit

Permalink
Merge pull request #225 from robertodr/bare-cmake
Browse files Browse the repository at this point in the history
Ensure that CMake and Python frontend script generate the same build system
  • Loading branch information
bast authored Mar 1, 2018
2 parents 0f3ee1a + 46e404f commit 945ba4e
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 29 deletions.
31 changes: 22 additions & 9 deletions .default.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
with import <nixpkgs> {}; {
autocmakeEnv = stdenv.mkDerivation {
let
hostPkgs = import <nixpkgs> {};
nixpkgs = (hostPkgs.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs-channels";
rev = "nixos-unstable";
sha256 = "15fcl29a97f68j1pjywmrjm31rdh1a21jz9airlsbzpl4lc3zhfi";
});
in
with import nixpkgs {};
stdenv.mkDerivation {
name = "Autocmake";
buildInputs = [
atlas
ccache
clang
cmake
doxygen
gcc
gfortran
liblapack
openmpi
python35Packages.pep8
python35Packages.pytest
python35Packages.pyyaml
pipenv
python3Packages.pep8
python3Packages.pytest
python3Packages.pyyaml
zlib
];
};
}
src = null;
shellHook = ''
export NINJA_STATUS="[Built edge %f of %t in %e sec]"
SOURCE_DATE_EPOCH=$(date +%s)
'';
}
6 changes: 0 additions & 6 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
use nix .default.nix
export SOURCE_DATE_EPOCH=$(date +%s)
dir_hash=autocmake-$(echo -n autocmake | shasum | cut -d ' ' -f 1)
direnv_layout_dir=$XDG_CACHE_HOME/direnv/layouts/$dir_hash
layout python `type -P python` --system-site-packages
pip install -r requirements.txt
export NINJA_STATUS="[Built edge %f of %t in %e sec]"
16 changes: 16 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[packages]

pycodestyle = "*"
pytest = "*"
PyYAML = "*"


[dev-packages]

92 changes: 92 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions autocmake/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ def autogenerated_notice():
return '\n'.join(s)


def gen_cmake_options_wrappers():
s = """\n# Options handling utilities
include(CMakeDependentOption)
# Macro for printing an option in a consistent manner
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# Syntax: print_option(<option to print> <was specified>)
macro(print_option variable default)
if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
message(STATUS "Setting (unspecified) option ${variable}: ${default}")
else()
message(STATUS "Setting option ${variable}: ${${variable}}")
endif()
endmacro()
# Wraps an option with default ON/OFF. Adds nice messaging to option()
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# Syntax: option_with_print(<option name> <description> <default value>)
macro(option_with_print variable msge default)
print_option(${variable} ${default})
option(${variable} ${msge} ${default})
endmacro(option_with_print)
# Wraps an option with a default other than ON/OFF and prints it
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# NOTE: Can\'t combine with above b/c CMake handles ON/OFF options specially
# NOTE2: CMake variables are always defined so need to further check for if
# they are the NULL string. This is also why weneed the force
# Syntax: option_with_default(<option name> <description> <default value>)
macro(option_with_default variable msge default)
print_option(${variable} "${default}")
if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
set(${variable} "${default}" CACHE STRING ${msge} FORCE)
endif()
endmacro(option_with_default)"""
return s


def gen_setup(config, default_build_type, relative_path, setup_script_name):
"""
Generate setup script.
Expand Down Expand Up @@ -148,6 +185,8 @@ def gen_cmakelists(project_name, project_language, min_cmake_version, default_bu
s.append(' set(CMAKE_BUILD_TYPE "{0}")'.format(_build_type))
s.append('endif()')

s.append(gen_cmake_options_wrappers())

if len(modules) > 0:
s.append('\n# directories which hold included cmake modules')

Expand Down
45 changes: 31 additions & 14 deletions modules/math_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,28 @@
# - "--blas=<BLAS> Detect and link BLAS library (auto or off) [default: auto]."
# - "--lapack=<LAPACK> Detect and link LAPACK library (auto or off) [default: auto]."
# - "--mkl=<MKL> Pass MKL flag to the Intel compiler and linker and skip BLAS/LAPACK detection (sequential, parallel, cluster, or off) [default: off]."
# - "--scalapack=<SCALAPACK_LIBRARIES> Link line for ScaLAPACK libraries [default: ]"
# - "--blacs=<BLACS_IMPLEMENTATION> Implementation of BLACS for MKL ScaLAPACK (openmpi, intelmpi, sgimpt) [default: openmpi]"
# define:
# - "'-DENABLE_BLAS={0}'.format(arguments['--blas'])"
# - "'-DENABLE_LAPACK={0}'.format(arguments['--lapack'])"
# - "'-DMKL_FLAG={0}'.format(arguments['--mkl'])"
# - "'-DMATH_LIB_SEARCH_ORDER=\"MKL;ESSL;OPENBLAS;ATLAS;ACML;SYSTEM_NATIVE\"'"
# - "'-DBLAS_LANG=Fortran'"
# - "'-DLAPACK_LANG=Fortran'"
# - "'-DSCALAPACK_LIBRARIES=\"{0}\"'.format(arguments['--scalapack'])"
# - "'-DBLACS_IMPLEMENTATION=\"{0}\"'.format(arguments['--blacs'])"
# warning: "the math_libs.cmake module is deprecated and will be removed in future versions"

option_with_default(ENABLE_BLAS "Enable BLAS autodetection" "auto")
option_with_default(ENABLE_LAPACK "Enable LAPACK autodetection" "auto")
option_with_default(MKL_FLAG "MKL flag for the Intel compiler and linker. Skips BLAS/LAPACK autodetection" "off")
option_with_default(MATH_LIB_SEARCH_ORDER "Search order for autodetection of math libraries" "MKL;ESSL;OPENBLAS;ATLAS;ACML;SYSTEM_NATIVE")
option_with_default(BLAS_LANG "Linker language for BLAS detection" "Fortran")
option_with_default(LAPACK_LANG "Linker language for LAPACK detection" "Fortran")
option_with_default(SCALAPACK_LIBRARIES "Link line for ScaLAPACK libraries" "")
option_with_default(BLACS_IMPLEMENTATION "Implementation of BLACS for MKL ScaLAPACK" "openmpi")

#-------------------------------------------------------------------------------
# ENABLE_STATIC_LINKING

Expand Down Expand Up @@ -197,7 +210,7 @@ if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
endif()
endif()

if(ENABLE_SCALAPACK)
if(ENABLE_SCALAPACK AND NOT SCALAPACK_LIBRARIES)
set(_scalapack_lib mkl_scalapack${_lib_suffix})
if(${BLACS_IMPLEMENTATION} STREQUAL "intelmpi")
set(_blacs_lib mkl_blacs_intelmpi${_lib_suffix})
Expand All @@ -211,6 +224,7 @@ if(ENABLE_SCALAPACK)
else()
set(_scalapack_lib)
set(_blacs_lib)
set(BLACS_IMPLEMENTATION)
endif()

# MKL 10.0.1.014
Expand Down Expand Up @@ -432,7 +446,7 @@ foreach(_service BLAS LAPACK)
endif()
endforeach()

if(NOT MKL_FLAG STREQUAL "off")
if(MKL_FLAG AND NOT MKL_FLAG STREQUAL "off")
set(EXTERNAL_LIBS ${EXTERNAL_LIBS} -mkl=${MKL_FLAG})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mkl=${MKL_FLAG}")
message(STATUS "User set explicit MKL flag which is passed to the compiler and linker: -mkl=${MKL_FLAG}")
Expand Down Expand Up @@ -495,12 +509,21 @@ foreach(_service BLAS LAPACK)
endforeach()

# first lapack, then blas as lapack might need blas routine
set(MATH_LIBS
${MATH_LIBS}
${LAPACK_LIBRARIES}
${BLAS_LIBRARIES}
CACHE STRING "Math libraries"
)
if(SCALAPACK_LIBRARIES)
list(APPEND MATH_LIBS
${MATH_LIBS}
${SCALAPACK_LIBRARIES}
${LAPACK_LIBRARIES}
${BLAS_LIBRARIES}
)
else()
list(APPEND MATH_LIBS
${MATH_LIBS}
${LAPACK_LIBRARIES}
${BLAS_LIBRARIES}
)
endif()
set(MATH_LIBS ${MATH_LIBS} CACHE STRING "Math libraries")

# further adaptation for the static linking
if (ENABLE_STATIC_LINKING)
Expand All @@ -519,9 +542,3 @@ if (ENABLE_STATIC_LINKING)
set(MATH_LIBS ${MATH_LIBS} -ldl)
endif()
endif()

if(MATH_LIB_SEARCH_ORDER)
# this print is here to avoid warning about MATH_LIB_SEARCH_ORDER which
# might be set but never used
message(STATUS "MATH_LIB_SEARCH_ORDER set to ${MATH_LIB_SEARCH_ORDER}")
endif()

0 comments on commit 945ba4e

Please sign in to comment.