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

Draft: Modernize CMake #34

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: ci

on:
push:
paths:
- "**.c"
- "**.cmake"
- "**/CMakeLists.txt"
- ".github/workflows/ci.yml"

jobs:

unix:

strategy:
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}
timeout-minutes: 5

steps:
- uses: actions/checkout@v4

- run: cmake --workflow --preset default

windows_msvc:
runs-on: windows-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v4

- run: cmake --workflow --preset msvc
69 changes: 48 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
cmake_minimum_required(VERSION 2.8)
project(GKlib C)
cmake_minimum_required(VERSION 3.14...3.28)

project(GKlib LANGUAGES C
VERSION 1.0.0
)

enable_testing()

option(BUILD_TESTING "Build tests" ON)

option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)

get_filename_component(abs "." ABSOLUTE)
set(GKLIB_PATH ${abs})
unset(abs)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND GKlib_IS_TOP_LEVEL)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/local" CACHE PATH "install prefix" FORCE)
endif()

set(CMAKE_C_STANDARD 99)

message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION} Arch: ${CMAKE_SYSTEM_PROCESSOR} install prefix: ${CMAKE_INSTALL_PREFIX}")

set(GKLIB_PATH ${PROJECT_SOURCE_DIR})

include(GKlibSystem.cmake)

include_directories(".")
if(MSVC)
include_directories("win32")
file(GLOB win32_sources RELATIVE "win32" "*.c")
else(MSVC)
set(win32_sources, "")
endif(MSVC)
set(win32_inc $<$<BOOL:${MSVC}>:${PROJECT_SOURCE_DIR}/win32>)
set(win32_sources $<$<BOOL:${MSVC}>:win32/adapt.c>)

set(GKlib_sources b64.c evaluate.c gkregex.c mcore.c seq.c
blas.c fkvkselect.c graph.c memory.c sort.c
cache.c fs.c htable.c pqueue.c string.c
csr.c getopt.c io.c random.c timers.c
error.c gk_util.c itemsets.c rw.c tokenizer.c)

add_library(GKlib ${GKlib_sources} ${win32_sources})
target_include_directories(GKlib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(GKlib PRIVATE
$<$<BOOL:${UNIX}>:m>
$<$<BOOL:${OPENMP}>:OpenMP::OpenMP_C>
)

add_library(GKlib::GKlib INTERFACE IMPORTED GLOBAL)
target_link_libraries(GKlib::GKlib INTERFACE GKlib)

if(BUILD_TESTING)
add_subdirectory(test)
endif()

if(UNIX)
target_link_libraries(GKlib m)
endif(UNIX)
install(TARGETS GKlib EXPORT ${PROJECT_NAME}-targets)

include_directories("test")
add_subdirectory("test")
install(FILES GKlib.h TYPE INCLUDE)
# must have trailing slash or it makes a vestigial subdir
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ TYPE INCLUDE
FILES_MATCHING PATTERN "gk_*.h")

install(TARGETS GKlib
ARCHIVE DESTINATION lib/${LINSTALL_PATH}
LIBRARY DESTINATION lib/${LINSTALL_PATH})
install(FILES ${GKlib_includes} DESTINATION include/${HINSTALL_PATH})
include(cmake/install.cmake)
114 changes: 114 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"version": 6,

"configurePresets": [
{
"name": "default",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_COMPILE_WARNING_AS_ERROR": true
}
},
{
"name": "msvc", "inherits": "default",
"generator": "Visual Studio 17 2022",
"cacheVariables": {
"CMAKE_COMPILE_WARNING_AS_ERROR": false
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
},
{
"name": "release",
"configurePreset": "default",
"configuration": "Release"
},
{
"name": "msvc-debug",
"configurePreset": "msvc",
"configuration": "Debug"
}
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"output": {
"outputOnFailure": true,
"verbosity": "verbose"
},
"execution": {
"noTestsAction": "error",
"scheduleRandom": true,
"stopOnFailure": false,
"timeout": 60
}
},
{
"name": "release", "inherits": "default",
"configuration": "Release"
},
{
"name": "msvc-debug", "inherits": "default",
"configurePreset": "msvc",
"configuration": "Debug"
}
],
"workflowPresets": [
{
"name": "default",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "default"
},
{
"type": "test",
"name": "default"
}
]
},
{
"name": "msvc",
"steps": [
{
"type": "configure",
"name": "msvc"
},
{
"type": "build",
"name": "msvc-debug"
},
{
"type": "test",
"name": "msvc-debug"
}
]
},
{
"name": "release",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "release"
},
{
"type": "test",
"name": "release"
}
]
}
]
}
Loading