Skip to content
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

cmake modernization to 1.2.x #203

Open
wants to merge 19 commits into
base: release/1.2
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@
# Copyright (c) 2015-2018 by Radovan Bast, Roberto Di Remigio, Jonas Juselius, and contributors.

# set minimum cmake version
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
cmake_policy(SET CMP0053 NEW)

# project name
project(PCMSolver LANGUAGES CXX C Fortran)
@@ -71,7 +72,8 @@ include(gperftools)
include(autocmake_int64)
include(autocmake_omp)
include(autocmake_safeguards)
include(autocmake_python_interpreter)
#include(autocmake_python_interpreter)
find_package(Python REQUIRED COMPONENTS Interpreter)
include(pcmsolver)
include(api)
include(autocmake_boost)
419 changes: 419 additions & 0 deletions THIRD-PARTY-LICENSES

Large diffs are not rendered by default.

193 changes: 95 additions & 98 deletions cmake/PCMSolverConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -7,16 +7,29 @@
# ::
#
# PCMSolver_FOUND - true if PCMSolver and all required components found on the system
# PCMSolver_VERSION - PCMSolver version in format Major.Minor.Release
# PCMSolver_VERSION - PCMSolver version in format Major.Minor.Release.
# PCMSolver_INCLUDE_DIRS - Directory where the PCMSolver/pcmsolver.h,
# PCMSolver/PCMInput.h headers and PCMSolver/pcmsolver.f90 source file are located.
# PCMSolver_INCLUDE_DIR - same as DIRS
# PCMSolver_DEFINITIONS: Definitions necessary to use PCMSolver, namely USING_PCMSolver.
# PCMSolver_LIBRARIES - PCMSolver library to link against.
# PCMSolver_LIBRARY - same as LIBRARIES
# PCMSolver_EXECUTABLE - path to PCMSolver executable
# Prefer targets.
# PCMSolver_INCLUDE_DIR - same as DIRS. Prefer targets.
# PCMSolver_DEFINITIONS: Definitions necessary to use PCMSolver, namely USING_PCMSolver. Prefer targets.
# PCMSolver_LIBRARIES - PCMSolver library to link against plus any dependent libraries. Prefer targets.
# PCMSolver_LIBRARY - same as LIBRARIES. Prefer targets.
# PCMSolver_EXECUTABLE - path to PCMSolver executable. Prefer targets.
# PCMSolver_PYMOD - path to PCMSolver python modules. Prefer target variable.
#
#
# Target variables:
#
# It is preferred to use properties set on the base target rather than using the above variables.
#
# ::
#
# PCMSolver_VERSION - (DNE) PCMSolver version in format Major.Minor.Release . Does not exist b/c computed at compile-time.
# PCMSolver_PYMOD - path to PCMSolver python modules
#
# get_property(_pym TARGET PCMSolver::pcm PROPERTY PCMSolver_PYMOD)
#
#
# Available components: shared static exe
#
@@ -31,18 +44,24 @@
#
# ::
#
# If PCMSolver is found, this module defines the following :prop_tgt:`IMPORTED`
# target. ::
# If PCMSolver is found and no language components are requested, this module
# defines at least the following :prop_tgt:`IMPORTED` target. ::
#
# PCMSolver::pcm - the main PCMSolver library with header & defs attached.
#
# If PCMSolver is found, depending on components requested and fullness of the
# installation, this module defines up to the following :prop_tgt:`IMPORTED` targets. ::
#
# PCMSolver::pcm - the main PCMSolver library with header & defs attached.
# PCMSolver::exe - the PCMSolver run_pcm program (COMPONENT exe)
#
#
# Suggested usage:
#
# ::
#
# find_package(PCMSolver)
# find_package(PCMSolver 1.1.7 CONFIG REQUIRED COMPONENTS shared)
# find_package(PCMSolver 1.2.3 CONFIG REQUIRED COMPONENTS shared)
#
#
# The following variables can be set to guide the search for this package:
@@ -54,111 +73,89 @@
# PATH - environment variable, set to bin directory of this package
# CMAKE_DISABLE_FIND_PACKAGE_PCMSolver - CMake variable, disables
# find_package(PCMSolver) perhaps to force internal build
#

@PACKAGE_INIT@

set(PN PCMSolver)
set (_valid_components
static
shared
exe
)
set(pcm PCMSolver) # NameSpace

# find includes
unset(_temp_h CACHE)
find_path(_temp_h
NAMES PCMSolver/pcmsolver.h
PATHS ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@
NO_DEFAULT_PATH)
if(_temp_h)
set(${PN}_INCLUDE_DIR "${_temp_h}")
set(${PN}_INCLUDE_DIRS ${${PN}_INCLUDE_DIR})
else()
set(${PN}_FOUND 0)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "${PN}Config missing component: header (${PN}: ${_temp_h})")
endif()
# check library style component
# * using EXISTS Targets-shared instead of @SHARED_LIBRARY_ONLY@ so packages can
# truncate their builds (e.g., build static for tests but only ship shared)
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${pcm}Targets-shared.cmake")
set(${pcm}_shared_FOUND 1)
endif()

# find executable
list(FIND ${PN}_FIND_COMPONENTS "exe" _seek_exe)
unset(_temp_exe CACHE)
find_program(_temp_exe
NAMES run_pcm
PATHS ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_BINDIR@
NO_DEFAULT_PATH)
if(_temp_exe)
set(${PN}_EXECUTABLE "{_temp_exe}")
if(_seek_exe GREATER -1)
set(${PN}_exe_FOUND 1)
endif()
else()
if(_seek_exe GREATER -1)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "${PN}Config missing component: executable (${PN}: ${_temp_exe})")
endif()
endif()
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${pcm}Targets-static.cmake")
set(${pcm}_static_FOUND 1)
endif()
list(FIND ${pcm}_FIND_COMPONENTS "shared" _seek_shared)
list(FIND ${pcm}_FIND_COMPONENTS "static" _seek_static)

# find library: shared, static, or whichever
set(_hold_library_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
list(FIND ${PN}_FIND_COMPONENTS "shared" _seek_shared)
list(FIND ${PN}_FIND_COMPONENTS "static" _seek_static)
if(_seek_shared GREATER -1)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
elseif(_seek_static GREATER -1)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
# check executable component
if (@BUILD_STANDALONE@ AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/${pcm}Targets-exe.cmake") # BUILD_STANDALONE
set(${pcm}_exe_FOUND 1)
endif()
unset(_temp CACHE)
find_library(_temp
NAMES pcm
PATHS ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@
NO_DEFAULT_PATH)
if(_temp)
set(${PN}_LIBRARY "${_temp}")
if(_seek_shared GREATER -1)
set(${PN}_shared_FOUND 1)
elseif(_seek_static GREATER -1)
set(${PN}_static_FOUND 1)
endif()
else()
if(_seek_shared GREATER -1)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "${PN}Config missing component: shared library (${PN}: ${_temp})")
endif()
elseif(_seek_static GREATER -1)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "${PN}Config missing component: static library (${PN}: ${_temp})")
endif()
else()
set(${PN}_FOUND 0)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "${PN}Config missing component: library (${PN}: ${_temp})")
endif()
endif()
list(FIND ${pcm}_FIND_COMPONENTS "exe" _seek_exe)

# check library dependency available
include(CMakeFindDependencyMacro)
if(NOT TARGET ZLIB::ZLIB)
find_dependency(ZLIB)
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_hold_library_suffixes})
set(${PN}_LIBRARIES ${${PN}_LIBRARY})
set(${PN}_DEFINITIONS USING_${PN})
set(${PN}_PYMOD ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@/@PYMOD_INSTALL_LIBDIR@)

check_required_components(${PN})
# Check all required components are available before trying to load any
check_required_components(${pcm})

#-----------------------------------------------------------------------------
# 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}::pcm)
get_filename_component(_fext ${${PN}_LIBRARY} EXT)
if(${_fext} STREQUAL ${CMAKE_SHARED_LIBRARY_SUFFIX})
include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets-shared.cmake")
else()
include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets-static.cmake")
if(NOT TARGET ${pcm}::pcm)
if(_seek_static GREATER -1)
include("${CMAKE_CURRENT_LIST_DIR}/${pcm}Targets-static.cmake")
elseif(_seek_shared GREATER -1)
include("${CMAKE_CURRENT_LIST_DIR}/${pcm}Targets-shared.cmake")
elseif(NOT @STATIC_LIBRARY_ONLY@) # STATIC_LIBRARY_ONLY
include("${CMAKE_CURRENT_LIST_DIR}/${pcm}Targets-shared.cmake")
elseif(NOT @SHARED_LIBRARY_ONLY@) # SHARED_LIBRARY_ONLY
include("${CMAKE_CURRENT_LIST_DIR}/${pcm}Targets-static.cmake")
endif()

include(CMakeFindDependencyMacro)
if(NOT TARGET ZLIB::ZLIB)
find_dependency(ZLIB)
get_property(_loc TARGET ${pcm}::pcm PROPERTY LOCATION)
get_property(_ill TARGET ${pcm}::pcm PROPERTY INTERFACE_LINK_LIBRARIES)
get_property(_iid TARGET ${pcm}::pcm PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(_icd TARGET ${pcm}::pcm PROPERTY INTERFACE_COMPILE_DEFINITIONS)
set(${pcm}_LIBRARY ${_loc})
set(${pcm}_LIBRARIES ${_loc};${_ill})
set(${pcm}_INCLUDE_DIR ${_iid})
set(${pcm}_INCLUDE_DIRS ${_iid})
set(${pcm}_DEFINITIONS ${_icd})

if(${pcm}_exe_FOUND)
include("${CMAKE_CURRENT_LIST_DIR}/${pcm}Targets-exe.cmake")
get_property(${pcm}_EXECUTABLE TARGET ${pcm}::exe PROPERTY LOCATION)
endif()
endif()

set(${pcm}_PYMOD ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@@PYMOD_INSTALL_LIBDIR@) # CMAKE_INSTALL_LIBDIR, PYMOD_INSTALL_LIBDIR

if (CMAKE_VERSION VERSION_GREATER 3.15)
message(VERBOSE "PCMSolver::pcm")

get_property(_ver TARGET ${pcm}::pcm PROPERTY PCMSolver_VERSION)
get_property(_pym TARGET ${pcm}::pcm PROPERTY PCMSolver_PYMOD)
message(VERBOSE "${pcm}::pcm.${pcm}_VERSION (DNE) ${_ver}")
message(VERBOSE "${pcm}::pcm.${pcm}_PYMOD ${_pym}")

message(VERBOSE "${pcm}_FOUND ${${pcm}_FOUND}")
message(VERBOSE "${pcm}_VERSION ${${pcm}_VERSION}")
message(VERBOSE "${pcm}_DEFINITIONS ${${pcm}_DEFINITIONS}")
message(VERBOSE "${pcm}_EXECUTABLE ${${pcm}_EXECUTABLE}")
message(VERBOSE "${pcm}_PYMOD ${${pcm}_PYMOD}")

message(VERBOSE "${pcm}_LIBRARY ${${pcm}_LIBRARY}")
message(VERBOSE "${pcm}_LIBRARIES ${${pcm}_LIBRARIES}")
message(VERBOSE "${pcm}_INCLUDE_DIR ${${pcm}_INCLUDE_DIR}")
message(VERBOSE "${pcm}_INCLUDE_DIRS ${${pcm}_INCLUDE_DIRS}")
endif()

endif()
2 changes: 1 addition & 1 deletion cmake/custom/compilers/CXXFlags.cmake
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ if(ENABLE_CXX11_SUPPORT)
RESULT cxx11_flag
LANGUAGE CXX
REQUIRED
FLAGS "-std=c++11;-std=c++0x;--c++11;--c++0x"
FLAGS "-std=c++11;/std:c++11;-std=c++0x;--c++11;--c++0x"
)
if(cxx11_flag)
set(CXX_STANDARD_FLAG ${cxx11_flag})
2 changes: 1 addition & 1 deletion cmake/custom/eigen.cmake
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
if(EIGEN3_ROOT)
set(EIGEN3_INCLUDE_DIR ${EIGEN3_ROOT}/include)
find_package(Eigen3 3.3.0)
message(STATUS "Eigen " ${EIGEN3_VERSION} " is located here: " ${EIGEN3_INCLUDE_DIR})
message(STATUS "Eigen FOUND " ${EIGEN3_VERSION_STRING} " is located here: " ${EIGEN3_INCLUDE_DIR})
if(NOT EIGEN3_FOUND)
set(EIGEN3_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/external/eigen3/include/eigen3)
message(STATUS "Eigen 3.3.2 is located here: " ${EIGEN3_INCLUDE_DIR})
2 changes: 1 addition & 1 deletion cmake/custom/find_python_module.cmake
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ macro(find_python_module module)
endif()
# A module's location is usually a directory, but for binary modules
# it's a .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
execute_process(COMMAND "${Python_EXECUTABLE}" "-c"
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
File renamed without changes.
16 changes: 8 additions & 8 deletions cmake/custom/pcmsolver.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option(ENABLE_LOGGER "Enable logger" OFF)
option(ENABLE_TIMER "Enable timer" ON)
option(BUILD_STANDALONE "Enable build of standalone executables" ON)
option_with_default(PCMSolver_INSTALL_CMAKEDIR "Directory to which PCMSolver CMake config files installed." share/cmake/${PROJECT_NAME})

# Add definitions
if(ENABLE_TIMER)
@@ -18,23 +19,22 @@ include(GNUInstallDirs)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
# Hardcode to share, rather than use CMAKE_INSTALL_DATAROOTDIR as the latter
# might resolve to a place not recognized by CMake
set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}")

set(CMAKECONFIG_INSTALL_DIR "${PCMSolver_INSTALL_CMAKEDIR}")

if(NOT DEFINED PYMOD_INSTALL_LIBDIR)
message(STATUS "Setting (unspecified) option PYMOD_INSTALL_LIBDIR: python")
set(PYMOD_INSTALL_LIBDIR "python" CACHE STRING "Location within CMAKE_INSTALL_LIBDIR to which Python modules are installed" FORCE)
message(STATUS "Setting (unspecified) option PYMOD_INSTALL_LIBDIR: /python")
set(PYMOD_INSTALL_LIBDIR "/python" CACHE STRING "Location within CMAKE_INSTALL_LIBDIR to which Python modules are installed" FORCE)
else()
message(STATUS "Setting option PYMOD_INSTALL_LIBDIR: ${PYMOD_INSTALL_LIBDIR}")
message(STATUS "Setting option PYMOD_INSTALL_LIBDIR (should start with /): ${PYMOD_INSTALL_LIBDIR}")
set(PYMOD_INSTALL_LIBDIR "${PYMOD_INSTALL_LIBDIR}" CACHE STRING "Location within CMAKE_INSTALL_LIBDIR to which Python modules are installed" FORCE)
endif()
file(TO_NATIVE_PATH "${CMAKE_INSTALL_LIBDIR}/${PYMOD_INSTALL_LIBDIR}/pcmsolver" PYMOD_INSTALL_FULLDIR)
file(TO_NATIVE_PATH "${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pcmsolver" PYMOD_INSTALL_FULLDIR)

add_custom_target(update_version
ALL
COMMAND
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/versioner.py
${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/versioner.py
--metaout ${CMAKE_CURRENT_BINARY_DIR}/metadata.py
--cmakeout ${CMAKE_CURRENT_BINARY_DIR}/metadata.cmake
--headerout ${CMAKE_CURRENT_BINARY_DIR}/include/VersionInfo.hpp
1 change: 1 addition & 0 deletions cmake/downloaded/autocmake_boost.cmake
Original file line number Diff line number Diff line change
@@ -104,6 +104,7 @@ else()
# Read from cache, needed for rebuilds
set(BOOST_INCLUDEDIR ${Boost_INCLUDE_DIR})
set(BOOST_LIBRARYDIR ${Boost_LIBRARY_DIR})
set(Boost_VERBOSE ON)
find_package(Boost ${BOOST_MINIMUM_REQUIRED} COMPONENTS "${BOOST_COMPONENTS_REQUIRED}")
if(NOT Boost_FOUND)
set(BUILD_CUSTOM_BOOST TRUE)
14 changes: 12 additions & 2 deletions cmake/downloaded/boost_cleanup.cmake
Original file line number Diff line number Diff line change
@@ -2,10 +2,20 @@
# licensed under BSD-3: https://github.com/coderefinery/autocmake/blob/master/LICENSE

# Clean-up
add_custom_command(
if(WIN32)
# observed trouble deleting the directory on Windows + MinGW + multiple builds
add_custom_command(
OUTPUT ${CUSTOM_BOOST_LOCATION}/boost.cleanedup
COMMAND ${CMAKE_COMMAND} -E remove_directory ${BOOST_BUILD_DIR}
COMMAND ${CMAKE_COMMAND} -E touch ${CUSTOM_BOOST_LOCATION}/boost.cleanedup
WORKING_DIRECTORY ${CUSTOM_BOOST_LOCATION}
DEPENDS ${CUSTOM_BOOST_LOCATION}/boost.installed
COMMENT "Clean-up Boost")
else()
add_custom_command(
OUTPUT ${CUSTOM_BOOST_LOCATION}/boost.cleanedup
COMMAND ${CMAKE_COMMAND} -E rm -r ${BOOST_BUILD_DIR}
COMMAND ${CMAKE_COMMAND} -E touch ${CUSTOM_BOOST_LOCATION}/boost.cleanedup
WORKING_DIRECTORY ${CUSTOM_BOOST_LOCATION}
DEPENDS ${CUSTOM_BOOST_LOCATION}/boost.installed
COMMENT "Clean-up Boost")
endif()
2 changes: 1 addition & 1 deletion cmake/downloaded/boost_configure.cmake
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ add_custom_command(
OUTPUT ${CUSTOM_BOOST_LOCATION}/boost.configured
COMMAND ./bootstrap.sh --with-toolset=${toolset}
${select_libraries}
--with-python=${PYTHON_EXECUTABLE}
--with-python=${Python_EXECUTABLE}
--prefix=${CUSTOM_BOOST_LOCATION} 1> ${CUSTOM_BOOST_LOCATION}/boost.configured.log 2> ${CUSTOM_BOOST_LOCATION}/boost.configured.err
COMMAND ${CMAKE_COMMAND} -E touch ${CUSTOM_BOOST_LOCATION}/boost.configured
WORKING_DIRECTORY ${BOOST_BUILD_DIR}
6 changes: 4 additions & 2 deletions external/Catch/catch.hpp
Original file line number Diff line number Diff line change
@@ -2056,8 +2056,10 @@ namespace Catch{
#define CATCH_TRAP() \
__asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
: : : "memory","r0","r3","r4" ) /* NOLINT */
#else
#define CATCH_TRAP() __asm__("int $3\n" : : /* NOLINT */ )
#elif defined(__i386__) || defined(__x86_64__)
#define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
#elif defined(__aarch64__)
#define CATCH_TRAP() __asm__(".inst 0xd4200000")
#endif

#elif defined(CATCH_PLATFORM_LINUX)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
--gperf Enable profiling with gperftools [default: False].
--int64 Enable 64bit integers [default: False].
--omp Enable OpenMP parallelization [default: False].
--python=<PYTHON_INTERPRETER> The Python interpreter (development version) to use. [default: ''].
--python=<Python_EXECUTABLE> The Python interpreter (development version) to use. [default: ''].
--fbindings=<TEST_Fortran_API> Enable testing of Fortran 90 API bindings <ON/OFF> [default: ON].
--boost-headers=<BOOST_INCLUDEDIR> Include directories for Boost [default: ''].
--boost-libraries=<BOOST_LIBRARYDIR> Library directories for Boost [default: ''].
@@ -65,7 +65,7 @@ def gen_cmake_command(options, arguments):
command.append('-DENABLE_GPERFTOOLS={0}'.format(arguments['--gperf']))
command.append('-DENABLE_64BIT_INTEGERS={0}'.format(arguments['--int64']))
command.append('-DENABLE_OPENMP={0}'.format(arguments['--omp']))
command.append('-DPYTHON_INTERPRETER="{0}"'.format(arguments['--python']))
command.append('-DPython_EXECUTABLE="{0}"'.format(arguments['--python']))
command.append('-DTEST_Fortran_API={0}'.format(arguments['--fbindings']))
command.append('-DBOOST_INCLUDEDIR="{0}"'.format(arguments['--boost-headers']))
command.append('-DBOOST_LIBRARYDIR="{0}"'.format(arguments['--boost-libraries']))
Loading