Skip to content

Commit

Permalink
Springclean CMake scripts and developer/client build/use interfaces (#13
Browse files Browse the repository at this point in the history
)

* Modernize minimize cmake/project settings

- Use version range for minimum CMake version

  Follow recommendation in:

  https://cliutils.gitlab.io/modern-cmake/chapters/basics.html

  to support current 3.8 minimum whilst always setting policy settings
  to those of the running version.

- Don't set policies which will automatically be NEW

- Let CMake fully handle versions without caching

  Caching allows user to set version values, but these are not
  user configurable values.

  Let CMake handle the setting of PTL_... and PROJECT_... version
  variables through the primary call to project() after version
  info has been read from VERSION file.

* Simplify PTL build/install with modern CMake tools

- Use modern CMake style of lowercase commands and empty else(),
  end...() commands
- Remove all unused custom functions and macros
  - Refactor remaining functionality into dedicated modules
- Remove obsolete/duplicate options and those that only apply to
  examples
- Only report relevant enabled features
  - Not possible to reliably report flags as these can change over
    the build tree
- Do not cache PTL_INSTALL_... variables, but allow override when
  PTL is a subproject, otherwise defaulting to the CMAKE_INSTALL_...
  equivalents
- Only expose ptl_add_option options when PTL is the primary project
  - parent projects can still set these manually
- Use compile features to export CXX Standard
  - Add cxx_std_<VERSION> to all targets built through ptl_build_library
    to ensure this usage requirement is propagated to clients.
  - Remove CMAKE_CXX_EXTENSIONS and CMAKE_CXX_STANDARD_REQUIRED from the
    cache as these should not be set by builders of the project.
  - Remove CMAKE_CXX_STANDARD setting in config files as the targets
    propagate this requirement.
- Do not default CMAKE_INSTALL_RPATH_USE_LINK_PATH setting
  This variable should be left up to the builder/installer as it
  hardcodes RPATH information that may not be wanted.
- Create header to propgate public preproc symbols
  PTL can be built with support for TBB and locks in user queues.
  These are enabled in code via #ifdef blocks on preprocessor symbols
  passed through -D flags. However, the choice is hardcoded at build
  time as it affects the API and ABI of the resultant PTL libraries.

  Promote TBB/Lock symbols to configured values in a new Config.hh file
  generated by CMake. Include this file in PTL code depending on the
  symbols. Install it along side other PTL headers.

  Remove setting of -D flags for TBB and locks from both public and
  private compile definitions.
- Update FindTBB module using version from VTK/Ogre, adding FPHSA support
- Link directly to Threads and TBB targets for simplicity and clarity
- Rationalize CMake/Build settings
  - Prefer use of CMAKE_.._FLAGS for passing sanitizer/coverage flags
    down the build tree. Whilst use of targets/usage requirements is
    preferred in modern CMake, it may not be the simplest solution for
    things like compiler flags that are pure BUILD_INTERFACE. Propagating
    flags through targets may result in these appearing in the install
    interface for the project. This may be confusing, or at worst, lead
    to unexpected behaviour.

    NB: Once CMake >= 3.13 is required, add_{compile,link}_options can
    be used instead.
- Unify build/install CMake config files
  - Handle primary target difference between build/install trees
    transparently via the PTLTargets.cmake file
  - Only use component arguments to find_package to decide on default
    for static/shared linking. Use of BUILD_{STATIC/SHARED}_LIBS may
    not result in the behaviour intended by the client project.
- Generate and install pkg-config file for PTL

* Make examples work with simplified CMake system

Comment out GPU example as it cannot currently build either with
updated CMake scripts or those on master

* Ensure build paths do not appear in installed CMake scripts

Set path to custom FindTBB module using a @PACKAGE_...@ variable
to that it will not export build tree information to the install
tree.

* Point CI Workflow to correct examples dir

* Fix typo + install libasan in CI scripts

* Removed libasan install + export sanitizer flags when address is used

* Use INTERFACE_LINK_OPTIONS instead of target_link_options

* export sanitizer link flags when not leak

* PTL_USE_ARCH removal from pyctest-runner

* Bumped version to 2.1.0

* Minor formatting updates

Co-authored-by: Jonathan R. Madsen <[email protected]>
  • Loading branch information
drbenmorgan and jrmadsen authored Oct 27, 2021
1 parent a978065 commit 50bc10a
Show file tree
Hide file tree
Showing 41 changed files with 1,168 additions and 2,858 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ jobs:
conda activate pyctest &&
export CMAKE_PREFIX_PATH="${HOME}/ptl-install:${CMAKE_PREFIX_PATH}:${CONDA_PREFIX}" &&
cmake --build build-PTL --target install &&
cmake -B ${HOME}/ptl-examples-build ${PWD}/examples/basic &&
cmake -B ${HOME}/ptl-examples-build ${PWD}/examples &&
cmake --build ${HOME}/ptl-examples-build --target all
107 changes: 46 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,110 +1,95 @@
################################################################################
# cmake settings
#
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
cmake_minimum_required(VERSION 3.8...3.20)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()

# Warn about an in-source build, but don't error out
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
set(MSG "")
message(STATUS "Warning! Building from the source directory is not recommended")
message(STATUS "If unintented, please remove 'CMakeCache.txt' and 'CMakeFiles'")
message(STATUS "and build from a separate directory")
message(WARNING "In-source build")
endif()

# Add allocation export symbol for the PLT module
add_compile_definitions(PTL_ALLOC_EXPORT)

cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0042 NEW)

# Check if project is being used directly or via add_subdirectory
set(PTL_MASTER_PROJECT ON)
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(PTL_MASTER_PROJECT OFF)
endif()

################################################################################
# version
#
# Version
file(READ "${CMAKE_CURRENT_LIST_DIR}/VERSION" VERSION_STRING LIMIT_COUNT 1)
string(REGEX REPLACE "(\n|\r)" "" VERSION_STRING "${VERSION_STRING}")
string(REGEX REPLACE "[A-Za-z].*" "" VERSION_STRING "${VERSION_STRING}")
set(PTL_VERSION "${VERSION_STRING}")


################################################################################
# project
# project setup
#
project(PTL LANGUAGES C CXX VERSION ${PTL_VERSION})
if(NOT PTL_MASTER_PROJECT)
unset(${PROJECT_NAME}_C_FLAGS CACHE)
unset(${PROJECT_NAME}_CXX_FLAGS CACHE)
endif()
set(CMAKE_DIRECTORY_LABELS "PTL")

################################################################################
#
#
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})

foreach(_TYPE MAJOR MINOR PATCH)
set(PTL_VERSION_${_TYPE} ${PROJECT_VERSION_${_TYPE}}
CACHE STRING "PTL ${_TYPE} version" FORCE)
mark_as_advanced(PTL_VERSION_${_TYPE})
endforeach()
set(PTL_VERSION_STRING "${PTL_VERSION_MAJOR}.${PTL_VERSION_MINOR}.${PTL_VERSION_PATCH}"
CACHE STRING "PTL version string")
# Postprocess version info to create variables for export to Version.hh
set(PTL_VERSION_STRING "${PTL_VERSION_MAJOR}.${PTL_VERSION_MINOR}.${PTL_VERSION_PATCH}")
math(EXPR PTL_VERSION_CODE
"10000 * ${PTL_VERSION_MAJOR} + 100 * ${PTL_VERSION_MINOR} + ${PTL_VERSION_PATCH}")

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME development)
mark_as_advanced(PTL_VERSION)

if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release CACHE STRING "CMake build type" FORCE)
endif()
# Project-local CMake settings
set(CMAKE_DIRECTORY_LABELS "PTL")
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME Development)
set(CMAKE_INSTALL_MESSAGE LAZY)
set(CMAKE_LINK_DEPENDS_NO_SHARED ON)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
include(PTLCMakeUtilities)

################################################################################

# include(MacroUtilities)
include(Options)
include(Compilers)
include(GNUInstallDirs)
include(ProjectSettings)
include(BuildSettings)
include(Packages)
include(ClangFormat)
# Build/Install settings and options
include(PTLInstallDirs)
include(PTLBuildSettings)

################################################################################
# PTL source
# User options
ptl_add_option(PTL_USE_TBB "Enable TBB" ON)
ptl_add_option(PTL_USE_LOCKS "Enable mutex locking in task subqueues for extra safety" OFF)

################################################################################
# Build Dependencies
# - Threads
if(NOT WIN32)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()
find_package(Threads REQUIRED)

add_subdirectory(source)
# - TBB
if(PTL_USE_TBB)
find_package(TBB 2017 REQUIRED)
endif()

################################################################################
# Installation and info
################################################################################
# PTL Primary Build
add_subdirectory(source)

include(ConfigurePackage)
################################################################################
# CMake/PkgConfig Support files
include(PTLPackageConfigHelpers)

if(PTL_BUILD_EXAMPLES)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/examples)
################################################################################
# Examples build/test
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/examples)
ptl_add_option(PTL_BUILD_EXAMPLES "Build examples" OFF)
if(PTL_BUILD_EXAMPLES)
set(PTL_DIR ${CMAKE_BINARY_DIR})
add_subdirectory(examples)
else()
set(PTL_BUILD_EXAMPLES OFF CACHE BOOL
"PTL examples directory doesn't exist" FORCE)
endif()
endif()

################################################################################
# Reporting if master project
if(PTL_MASTER_PROJECT)
ptl_print_features()
else()
set(${PROJECT_NAME}_C_FLAGS ${${PROJECT_NAME}_C_FLAGS} CACHE STRING
"C compiler flags for ${PROJECT_NAME}")
set(${PROJECT_NAME}_CXX_FLAGS ${${PROJECT_NAME}_CXX_FLAGS} CACHE STRING
"CXX compiler flags for ${PROJECT_NAME}")
endif()

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.2
2.1.0
89 changes: 0 additions & 89 deletions cmake/Modules/BuildSettings.cmake

This file was deleted.

51 changes: 0 additions & 51 deletions cmake/Modules/ClangFormat.cmake

This file was deleted.

Loading

0 comments on commit 50bc10a

Please sign in to comment.