Skip to content
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
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: ci

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

# avoid wasted runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true


jobs:

unix:

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

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

steps:
- &checkout
uses: actions/checkout@v4

- run: cmake --workflow default

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

steps:
- *checkout

- run: cmake --workflow release
77 changes: 55 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
cmake_minimum_required(VERSION 2.8)
project(GKlib C)
cmake_minimum_required(VERSION 3.16...4.1)

option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED ENV{CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
endif()

project(GKlib LANGUAGES C
VERSION 1.0.0
)

enable_testing()

include(GNUInstallDirs)

option(BUILD_TESTING "Build tests")

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

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})

get_filename_component(abs "." ABSOLUTE)
set(GKLIB_PATH ${abs})
unset(abs)
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:${CMAKE_INSTALL_INCLUDEDIR}>
)
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)
80 changes: 80 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"version": 6,

"configurePresets": [
{
"name": "default",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"BUILD_TESTING": true
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
},
{
"name": "release",
"configurePreset": "default",
"configuration": "Release"
}
],
"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"
}
],
"workflowPresets": [
{
"name": "default",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "default"
},
{
"type": "test",
"name": "default"
}
]
},
{
"name": "release",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "release"
},
{
"type": "test",
"name": "release"
}
]
}
]
}
134 changes: 37 additions & 97 deletions GKlibSystem.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,150 +3,90 @@ include(CheckFunctionExists)
include(CheckIncludeFile)

# Setup options.
option(GDB "enable use of GDB" OFF)
option(ASSERT "turn asserts on" OFF)
option(ASSERT2 "additional assertions" OFF)
option(DEBUG "add debugging support" OFF)
option(GPROF "add gprof support" OFF)
option(VALGRIND "add valgrind support" OFF)
option(OPENMP "enable OpenMP support" OFF)
option(PCRE "enable PCRE support" OFF)
option(GKREGEX "enable GKREGEX support" OFF)
option(GKRAND "enable GKRAND support" OFF)
option(NO_X86 "enable NO_X86 support" OFF)


# Add compiler flags.
if(MSVC)
set(GKlib_COPTS "/Ox")
set(GKlib_COPTIONS "-DWIN32 -DMSC -D_CRT_SECURE_NO_DEPRECATE -DUSE_GKREGEX")
elseif(MINGW)
set(GKlib_COPTS "-DUSE_GKREGEX")
set(GKlib_COPTIONS WIN32 MSC _CRT_SECURE_NO_DEPRECATE USE_GKREGEX)
elseif(WIN32)
set(GKlib_COPTIONS USE_GKREGEX)
else()
set(GKlib_COPTIONS "-DLINUX -D_FILE_OFFSET_BITS=64")
set(GKlib_COPTIONS LINUX FILE_OFFSET_BITS=64)
endif(MSVC)

if(CYGWIN)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DCYGWIN")
endif(CYGWIN)
if(CMAKE_COMPILER_IS_GNUCC)
# GCC opts.
set(GKlib_COPTIONS "${GKlib_COPTIONS} -std=c99 -fno-strict-aliasing")
if(VALGRIND)
set(GKlib_COPTIONS "${GK_COPTIONS} -march=x86-64 -mtune=generic")
else()
# -march=native is not a valid flag on PPC:
if(CMAKE_SYSTEM_PROCESSOR MATCHES "power|ppc|powerpc|ppc64|powerpc64" OR (APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES "ppc|ppc64"))
set(GKlib_COPTIONS "${GKlib_COPTIONS} -mtune=native")
else()
set(GKlib_COPTIONS "${GKlib_COPTIONS} -march=native")
list(APPEND GKlib_COPTIONS CYGWIN)
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
list(APPEND GKlib_COPTS -fno-strict-aliasing -Wall -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unknown-pragmas -Wno-unused-label)
endif()
endif(VALGRIND)
if(NOT MINGW)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -fPIC")
endif(NOT MINGW)
# GCC warnings.
set(GKlib_COPTIONS "${GKlib_COPTIONS} -Werror -Wall -pedantic -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unknown-pragmas -Wno-unused-label")
elseif(${CMAKE_C_COMPILER_ID} MATCHES "Sun")
# Sun insists on -xc99.
set(GKlib_COPTIONS "${GKlib_COPTIONS} -xc99")
endif(CMAKE_COMPILER_IS_GNUCC)

# Intel compiler
if(${CMAKE_C_COMPILER_ID} MATCHES "Intel")
set(GKlib_COPTIONS "${GKlib_COPTIONS} -xHost -std=c99")

if(UNIX)
include(CheckPIESupported)
check_pie_supported()
set(CMAKE_POSITION_INDEPENDENT_CODE true)
endif()

# Find OpenMP if it is requested.
if(OPENMP)
include(FindOpenMP)
if(OPENMP_FOUND)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -D__OPENMP__ ${OpenMP_C_FLAGS}")
else()
message(WARNING "OpenMP was requested but support was not found")
endif(OPENMP_FOUND)
endif(OPENMP)

# Set the CPU type
if(NO_X86)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DNO_X86=${NO_X86}")
endif(NO_X86)

# Add various definitions.
if(GDB)
set(GKlib_COPTS "${GKlib_COPTS} -g")
set(GKlib_COPTIONS "${GKlib_COPTIONS} -Werror")
else()
set(GKlib_COPTS "-O3")
endif(GDB)


if(DEBUG)
set(GKlib_COPTS "-g")
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DDEBUG")
endif(DEBUG)

if(GPROF)
set(GKlib_COPTS "-pg")
endif(GPROF)

if(NOT ASSERT)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DNDEBUG")
endif(NOT ASSERT)

if(NOT ASSERT2)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DNDEBUG2")
endif(NOT ASSERT2)
find_package(OpenMP REQUIRED)
list(APPEND GKlib_COPTIONS __OPENMP__)
endif()

# Set the CPU type
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
list(APPEND GKlib_COPTIONS NO_X86=1)
endif()

# Add various options
if(PCRE)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -D__WITHPCRE__")
endif(PCRE)
list(APPEND GKlib_COPTIONS __WITHPCRE__)
endif()

if(GKREGEX)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DUSE_GKREGEX")
endif(GKREGEX)
list(APPEND GKlib_COPTIONS USE_GKREGEX)
endif()

if(GKRAND)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DUSE_GKRAND")
endif(GKRAND)
list(APPEND GKlib_COPTIONS USE_GKRAND)
endif()


# Check for features.
check_include_file(execinfo.h HAVE_EXECINFO_H)
if(HAVE_EXECINFO_H)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DHAVE_EXECINFO_H")
list(APPEND GKlib_COPTIONS HAVE_EXECINFO_H)
endif(HAVE_EXECINFO_H)

check_function_exists(getline HAVE_GETLINE)
if(HAVE_GETLINE)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -DHAVE_GETLINE")
list(APPEND GKlib_COPTIONS HAVE_GETLINE)
endif(HAVE_GETLINE)


# Custom check for TLS.
if(MSVC)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -D__thread=__declspec(thread)")

# This if checks if that value is cached or not.
if("${HAVE_THREADLOCALSTORAGE}" MATCHES "^${HAVE_THREADLOCALSTORAGE}$")
if(NOT DEFINED HAVE_THREADLOCALSTORAGE)
message(CHECK_START "checking for thread-local storage")
try_compile(HAVE_THREADLOCALSTORAGE
${CMAKE_BINARY_DIR}
${GKLIB_PATH}/conf/check_thread_storage.c)
if(HAVE_THREADLOCALSTORAGE)
message(STATUS "checking for thread-local storage - found")
message(CHECK_PASS "found")
else()
message(STATUS "checking for thread-local storage - not found")
message(CHECK_FAIL "not found")
endif()
endif()
if(NOT HAVE_THREADLOCALSTORAGE)
set(GKlib_COPTIONS "${GKlib_COPTIONS} -D__thread=")
list(APPEND GKlib_COPTIONS __thread=)
endif()
endif()

# Finally set the official C flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GKlib_COPTIONS} ${GKlib_COPTS}")

# Find GKlib sources.
file(GLOB GKlib_sources ${GKLIB_PATH}/*.c)
file(GLOB GKlib_includes ${GKLIB_PATH}/*.h)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${GKlib_COPTS}>")
add_compile_definitions("$<$<COMPILE_LANGUAGE:C>:${GKlib_COPTIONS}>")
Loading