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

Project modernization #33

Open
wants to merge 17 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
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
workflow_dispatch:
pull_request:
branches: [ master ]
push:
branches: [ master ]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
uses: ./.github/workflows/step_test.yaml

pass:
needs: [ tests ]
runs-on: ubuntu-latest
steps:
- name: Check all CI jobs
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
if: always()
62 changes: 62 additions & 0 deletions .github/workflows/step_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: test
run-name: Run tests

on:
workflow_call:

permissions:
contents: read

jobs:
tests:
name: Check ${{ matrix.toolchain }}
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
container: ${{ !matrix.os && 'ghcr.io/lecrisut/dev-env:main' || '' }}
continue-on-error: ${{ matrix.experimental || false }}
strategy:
fail-fast: false
matrix:
toolchain: [ gcc, llvm, intel, windows, macos ]
openmp: [ ON, OFF ]
include:
- os: windows-latest
toolchain: windows
# Need to find how to install on windows
experimental: true
- os: macos-latest
toolchain: macos
- os: macos-latest
toolchain: macos
openmp: ON
# Need to find how to install openmp on macos
experimental: true
env:
WITH_OPENMP: ${{ matrix.openmp }}
steps:
- name: Enable msvc toolchain on windows
uses: ilammy/msvc-dev-cmd@v1
if: contains(matrix.os, 'windows')
- name: Activate Intel compilers
# Not elegant, it will propagate all environment variable.
# Intel does not provide a way to output the environment variables to a file
# Note: PATH needs to be exported to GITHUB_PATH otherwise it can be overwritten
run: |
source /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
echo $PATH >> $GITHUB_PATH
if: matrix.toolchain == 'intel'
- uses: actions/checkout@v4
- uses: lukka/get-cmake@latest
- name: Run CMake configuration for ${{ matrix.toolchain }} toolchain
uses: lukka/[email protected]
with:
workflowPreset: "${{ matrix.toolchain }}-ci"
pass:
needs: [ tests ]
runs-on: ubuntu-latest
steps:
- name: Check test jobs
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
if: always()
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ dkms.conf
build/
lib/
.svn/

### Project specific
CMakeUserPresets.json
cmake-build-*
226 changes: 202 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,209 @@
cmake_minimum_required(VERSION 2.8)
project(GKlib C)
cmake_minimum_required(VERSION 3.15)
# CMake version compatibility
# TODO: Remove when cmake 3.25 is commonly distributed
if (POLICY CMP0140)
cmake_policy(SET CMP0140 NEW)
endif ()

option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)
#[==============================================================================================[
# Basic project definition #
]==============================================================================================]

get_filename_component(abs "." ABSOLUTE)
set(GKLIB_PATH ${abs})
unset(abs)
include(GKlibSystem.cmake)
list(APPEND CMAKE_MESSAGE_CONTEXT GKlib)
project(GKlib
VERSION 5.3.0
DESCRIPTION "A library of various helper routines and frameworks used by many of the KarypisLab's software"
HOMEPAGE_URL https://github.com/KarypisLab/GKlib
LANGUAGES C
)

include_directories(".")
if(MSVC)
include_directories("win32")
file(GLOB win32_sources RELATIVE "win32" "*.c")
else(MSVC)
set(win32_sources, "")
endif(MSVC)
# Back-porting to PROJECT_IS_TOP_LEVEL to older cmake
# TODO: Remove when requiring cmake >= 3.21
if (NOT DEFINED Spglib_IS_TOP_LEVEL)
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(PROJECT_IS_TOP_LEVEL ON)
else ()
set(PROJECT_IS_TOP_LEVEL OFF)
endif ()
endif ()

add_library(GKlib ${GKlib_sources} ${win32_sources})
# Specify C standard
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)

if(UNIX)
target_link_libraries(GKlib m)
endif(UNIX)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()

include_directories("test")
add_subdirectory("test")
#[==============================================================================================[
# Options #
]==============================================================================================]

install(TARGETS GKlib
ARCHIVE DESTINATION lib/${LINSTALL_PATH}
LIBRARY DESTINATION lib/${LINSTALL_PATH})
install(FILES ${GKlib_includes} DESTINATION include/${HINSTALL_PATH})
include(CMakeDependentOption)
include(FeatureSummary)
option(GKLIB_TESTS "GKlib: Build unit tests" ${PROJECT_IS_TOP_LEVEL})
option(GKLIB_SHARED_LIBS "GKlib: Build as a shared library" ${PROJECT_IS_TOP_LEVEL})
option(GKLIB_INSTALL "GKlib: Install project" ${PROJECT_IS_TOP_LEVEL})

# TODO: Discuss these options. Non-standard and easily conflicting
option(GKLIB_ASSERT "GKlib: Turn asserts on" OFF)
option(GKLIB_ASSERT2 "GKlib: Additional assertions" OFF)
option(GKLIB_NO_X86 "GKlib: Enable NO_X86 support" ON)
option(GKLIB_GPROF "GKlib: Add gprof support" OFF)

option(GKLIB_OpenMP "GKlib: Enable OpenMP support" OFF)
add_feature_info(GKLIB_OpenMP GKLIB_OpenMP "OpenMP support")
option(GKLIB_PCRE "GKlib: Enable PCRE support" OFF)
add_feature_info(GKLIB_PCRE GKLIB_PCRE "PCRE support")
cmake_dependent_option(GKLIB_GKREGEX "GKlib: Enable GKREGEX support" OFF "NOT GKLIB_PCRE" OFF)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic error here, it should be

Need to add `-GKLIB_GKREGEX=ON`
```cmake
# Second "OFF" should be "ON"
cmake_dependent_option(GKLIB_GKREGEX "GKlib: Enable GKREGEX support" OFF "NOT GKLIB_PCRE" ON)

add_feature_info(GKLIB_GKREGEX GKLIB_GKREGEX "GKREGEX support")
option(GKLIB_GKRAND "GKlib: Enable GKRAND support" OFF)
add_feature_info(GKLIB_GKRAND GKLIB_GKRAND "GKRAND support")

#[==============================================================================================[
# Project configuration #
]==============================================================================================]

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# Include basic tools
include(FetchContent)
if (GKLIB_INSTALL)
include(CMakePackageConfigHelpers)
if (UNIX)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be unconditional, it's not an issue for this on Windows. And also, you use e.g. CMAKE_INSTALL_BINDIR unconditionally later on which expands to nothing on Windows currently.

include(GNUInstallDirs)
endif ()
endif ()

# Define basic parameters
set(BUILD_SHARED_LIBS ${GKLIB_SHARED_LIBS})

#[==============================================================================================[
# External packages #
]==============================================================================================]

if (GKLIB_OpenMP)
# Normally these packages are pulled outside of if statements to allow to be added optionally.
# Making an exception for basic packages like OpenMP, MPI, etc. that drastically change a
# library's implementation and expected behaviour
find_package(OpenMP COMPONENTS C)
set_package_properties(OpenMP PROPERTIES TYPE REQUIRED)
endif ()
if (GKLIB_PCRE)
# TODO: This option should be obsolete and moved to optional find_package control
# TODO: Move to PCRE2, since PCRE1 is dead
# find_package(pcre2 COMPONENTS POSIX)
# set_package_properties(pcre2 PROPERTIES TYPE REQUIRED)
endif ()
include(GKlib_PackagesInfo)

feature_summary(
FILENAME ${CMAKE_CURRENT_BINARY_DIR}/GKlib.info
VAR GKlib_Info
DESCRIPTION "GKlib supported libraries"
FATAL_ON_MISSING_REQUIRED_PACKAGES
WHAT ALL
)
message(STATUS ${GKlib_Info})

#[==============================================================================================[
# Main definition #
]==============================================================================================]

# Main project
add_library(GKlib_GKlib)
set_target_properties(GKlib_GKlib PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
EXPORT_NAME GKlib
OUTPUT_NAME gk
)
add_library(GKlib::GKlib ALIAS GKlib_GKlib)
add_subdirectory(include)
add_subdirectory(src)


if (GKLIB_TESTS)
enable_testing()
add_subdirectory(test)
endif ()

#[==============================================================================================[
# Install or Export #
]==============================================================================================]

# Installation
if (GKLIB_INSTALL)
# pkg-config files
# TODO: Figure how to make this work
# file(GENERATE OUTPUT gklib.pc
# INPUT cmake/gklib.pc.in
# )
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gklib.pc
# DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
# COMPONENT GKlib_Development
# )

# cmake export files
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/GKlibConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
cmake/GKlibConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/GKlibConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/GKlib
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GKlibConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/GKlibConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/GKlib
COMPONENT GKlib_Development
)
export(EXPORT GKlibTargets
FILE GKlibTargets.cmake
NAMESPACE GKlib::
)
install(EXPORT GKlibTargets
FILE GKlibTargets.cmake
NAMESPACE GKlib::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/GKlib
COMPONENT GKlib_Development
)
endif ()

# Make project available for FetchContent
if (NOT PROJECT_IS_TOP_LEVEL)
# Set variables for FetchContent
# All variables have to be consistent with GKlibConfig.cmake
set(GKlib_OpenMP GKLIB_OpenMP)
set(GKlib_PCRE GKLIB_PCRE)
set(GKlib_GKREGEX GKLIB_GKREGEX)
set(GKlib_GKRAND GKLIB_GKRAND)
# Propagate variables
if (CMAKE_VERSION VERSION_LESS 3.25)
# TODO: Remove when cmake 3.25 is commonly distributed
set(GKlib_VERSION ${GKlib_VERSION} PARENT_SCOPE)
set(GKlib_VERSION_MAJOR ${GKlib_VERSION_MAJOR} PARENT_SCOPE)
set(GKlib_VERSION_MINOR ${GKlib_VERSION_MINOR} PARENT_SCOPE)
set(GKlib_VERSION_PATCH ${GKlib_VERSION_PATCH} PARENT_SCOPE)
set(GKlib_VERSION_TWEAK ${GKlib_VERSION_TWEAK} PARENT_SCOPE)
set(GKlib_OpenMP ${GKlib_OpenMP} PARENT_SCOPE)
set(GKlib_PCRE ${GKlib_PCRE} PARENT_SCOPE)
set(GKlib_GKREGEX ${GKlib_GKREGEX} PARENT_SCOPE)
set(GKlib_GKRAND ${GKlib_GKRAND} PARENT_SCOPE)
else ()
return(PROPAGATE
GKlib_VERSION
GKlib_VERSION_MAJOR
GKlib_VERSION_MINOR
GKlib_VERSION_PATCH
GKlib_VERSION_TWEAK
GKlib_OpenMP
GKlib_PCRE
GKlib_GKREGEX
GKlib_GKRAND
)
endif ()
endif ()
12 changes: 12 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"include": [
"cmake/CMakePresets-defaults.json",
"cmake/CMakePresets-CI.json"
]
}
Loading