From c82543dd632314ac40762cc2d72c2174f5305c46 Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 8 Dec 2023 10:06:24 -0500 Subject: [PATCH 01/10] cmake modern style --- CMakeLists.txt | 42 ++++++++++++++++++++---------------------- GKlibSystem.cmake | 8 ++------ 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cd1b4b..3312735 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,29 @@ -cmake_minimum_required(VERSION 2.8) -project(GKlib C) +cmake_minimum_required(VERSION 3.14...3.28) +project(GKlib LANGUAGES C) 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) +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 $<$:${PROJECT_SOURCE_DIR}/win32>) +set(win32_sources $<$:win32/adapt.c>) -add_library(GKlib ${GKlib_sources} ${win32_sources}) +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) -if(UNIX) - target_link_libraries(GKlib m) -endif(UNIX) +add_library(GKlib ${GKlib_sources} ${win32_sources}) +target_include_directories(GKlib PUBLIC +$ +$ +) +target_link_libraries(GKlib PRIVATE $<$:m>) -include_directories("test") -add_subdirectory("test") +add_subdirectory(test) -install(TARGETS GKlib - ARCHIVE DESTINATION lib/${LINSTALL_PATH} - LIBRARY DESTINATION lib/${LINSTALL_PATH}) -install(FILES ${GKlib_includes} DESTINATION include/${HINSTALL_PATH}) +install(TARGETS GKlib) +install(FILES ${GKlib_includes} TYPE INCLUDE) diff --git a/GKlibSystem.cmake b/GKlibSystem.cmake index 31a1cf1..d310bdd 100644 --- a/GKlibSystem.cmake +++ b/GKlibSystem.cmake @@ -66,7 +66,7 @@ if(OPENMP) endif(OPENMP_FOUND) endif(OPENMP) -# Set the CPU type +# Set the CPU type if(NO_X86) set(GKlib_COPTIONS "${GKlib_COPTIONS} -DNO_X86=${NO_X86}") endif(NO_X86) @@ -145,8 +145,4 @@ if(MSVC) 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("$<$:${GKlib_COPTIONS};${GKlib_COPTS}>") From 96d4591865acc8202731077295c01b80ca146fd6 Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 8 Dec 2023 10:20:10 -0500 Subject: [PATCH 02/10] correct build options --- CMakeLists.txt | 9 +++- GKlibSystem.cmake | 125 +++++++++++++--------------------------------- 2 files changed, 44 insertions(+), 90 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3312735..e4d3c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,10 @@ project(GKlib LANGUAGES C) option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF) +set(CMAKE_C_STANDARD 99) + +message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} Arch: ${CMAKE_SYSTEM_PROCESSOR}") + set(GKLIB_PATH ${PROJECT_SOURCE_DIR}) include(GKlibSystem.cmake) @@ -21,7 +25,10 @@ target_include_directories(GKlib PUBLIC $ $ ) -target_link_libraries(GKlib PRIVATE $<$:m>) +target_link_libraries(GKlib PRIVATE +$<$:m> +$<$:OpenMP::OpenMP_C> +) add_subdirectory(test) diff --git a/GKlibSystem.cmake b/GKlibSystem.cmake index d310bdd..3081ec9 100644 --- a/GKlibSystem.cmake +++ b/GKlibSystem.cmake @@ -3,146 +3,93 @@ 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() -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(CMAKE_C_COMPILER_ID STREQUAL "GNU") + list(APPEND GKlib_COPTS -fno-strict-aliasing -Werror -Wall -pedantic -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unknown-pragmas -Wno-unused-label) +endif() + +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) + find_package(OpenMP REQUIRED) + list(APPEND GKlib_COPTIONS __OPENMP__) +endif() # 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) - +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)") + list(APPEND GKlib_COPTIONS __thread=__declspec(thread)) # This if checks if that value is cached or not. if("${HAVE_THREADLOCALSTORAGE}" MATCHES "^${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. -add_compile_options("$<$:${GKlib_COPTIONS};${GKlib_COPTS}>") +add_compile_options("$<$:${GKlib_COPTS}>") +add_compile_definitions("$<$:${GKlib_COPTIONS}>") From a99cbfc6b04b907489336d2046980450d773bffb Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 8 Dec 2023 10:20:38 -0500 Subject: [PATCH 03/10] add CI --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7af9cc4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: ci + +on: + push: + paths: + - "**.c" + - "**.cmake" + - "**/CMakeLists.txt" + - ".github/workflows/ci.yml" + +jobs: + + unix: + + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + intsize: [32, 64] + + runs-on: ${{ matrix.os }} + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v4 + + - run: cmake -B build -Dintsize=${{ matrix.intsize }} + - run: cmake --build build --parallel + + - run: ctest --test-dir build -V + + + windows_msvc: + runs-on: windows-latest + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v4 + + - run: cmake -B build + + - run: cmake --build build --config Release --parallel + + - run: ctest --test-dir build -C Release -V From e54bade483435190c0683e19a44063b3d3c298cc Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 8 Dec 2023 10:24:07 -0500 Subject: [PATCH 04/10] ci: use presets --- .github/workflows/ci.yml | 13 +---- CMakePresets.json | 114 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 CMakePresets.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7af9cc4..5d5fe99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,6 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - intsize: [32, 64] runs-on: ${{ matrix.os }} timeout-minutes: 5 @@ -23,11 +22,7 @@ jobs: steps: - uses: actions/checkout@v4 - - run: cmake -B build -Dintsize=${{ matrix.intsize }} - - run: cmake --build build --parallel - - - run: ctest --test-dir build -V - + - run: cmake --workflow --preset default windows_msvc: runs-on: windows-latest @@ -36,8 +31,4 @@ jobs: steps: - uses: actions/checkout@v4 - - run: cmake -B build - - - run: cmake --build build --config Release --parallel - - - run: ctest --test-dir build -C Release -V + - run: cmake --workflow --preset msvc diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..cd2d240 --- /dev/null +++ b/CMakePresets.json @@ -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" + } + ] + } +] +} From 8fd78b0e388d7088e1aabed1a987d3b329833eef Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 8 Dec 2023 10:25:09 -0500 Subject: [PATCH 05/10] badge --- README.md | 53 +++++------------------------------------------------ 1 file changed, 5 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index f94eeea..d1bb0a0 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,11 @@ # GKlib -A library of various helper routines and frameworks used by many of the lab's software -## Build requirements - - CMake 2.8, found at http://www.cmake.org/, as well as GNU make. - -Assuming that the above are available, two commands should suffice to -build the software: -``` -make config -make -``` - -## Configuring the build -It is primarily configured by passing options to make config. For example: -``` -make config cc=icc -``` - -would configure it to be built using icc. - -Configuration options are: -``` -cc=[compiler] - The C compiler to use [default: gcc] -prefix=[PATH] - Set the installation prefix [default: ~/local] -openmp=set - To build a version with OpenMP support -``` +[![ci](https://github.com/scivision/GKlib/actions/workflows/ci.yml/badge.svg)](https://github.com/scivision/GKlib/actions/workflows/ci.yml) +A library of various helper routines and frameworks used by many of the lab's software. -## Building and installing -To build and install, run the following -``` -make -make install -``` +This has been enhanced to work on modern computers with modern CMake. -By default, the library file, header file, and binaries will be installed in +```sh +cmake --workflow --preset default ``` -~/local/lib -~/local/include -~/local/bin -``` - -## Other make commands - make uninstall - Removes all files installed by 'make install'. - - make clean - Removes all object files but retains the configuration options. - - make distclean - Performs clean and completely removes the build directory. - - From 44630ca3e606252d40a1af61b786222a812f0a4f Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 8 Dec 2023 10:50:39 -0500 Subject: [PATCH 06/10] add self-testing --- CMakeLists.txt | 5 +++++ test/CMakeLists.txt | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4d3c46..353be44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.14...3.28) project(GKlib LANGUAGES C) +enable_testing() + +option(BUILD_TESTING "Build tests" ON) option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF) @@ -30,7 +33,9 @@ $<$:m> $<$:OpenMP::OpenMP_C> ) +if(BUILD_TESTING) add_subdirectory(test) +endif() install(TARGETS GKlib) install(FILES ${GKlib_includes} TYPE INCLUDE) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8584820..5cc05ed 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,9 +11,12 @@ add_executable(cmpnbrs cmpnbrs.c) add_executable(splatt2svd splatt2svd.c) add_executable(gkuniq gkuniq.c) -foreach(prog strings gksort fis gkrw gkgraph csrcnv grKx m2mnbrs cmpnbrs splatt2svd gkuniq) - target_link_libraries(${prog} GKlib) -endforeach(prog) +foreach(prog IN ITEMS strings gksort fis gkrw gkgraph csrcnv grKx m2mnbrs cmpnbrs splatt2svd gkuniq) + target_link_libraries(${prog} PRIVATE GKlib) + if(NOT prog MATCHES "m2mnbrs|cmpnbrs|splatt2svd") + add_test(NAME ${prog} COMMAND ${prog}) + endif() +endforeach() # Install a subset of them -install(TARGETS csrcnv RUNTIME DESTINATION bin) +install(TARGETS csrcnv) From 078042614ff5192ab4c9bde0575bfef0d4572687 Mon Sep 17 00:00:00 2001 From: scivision Date: Wed, 20 Dec 2023 19:55:27 -0500 Subject: [PATCH 07/10] install meta add Global imported GKlib::GKlib --- CMakeLists.txt | 25 +++++++++++++++++---- LICENSE.txt => LICENSE | 5 ++--- cmake/config.cmake.in | 9 ++++++++ cmake/install.cmake | 50 ++++++++++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 3 --- 5 files changed, 82 insertions(+), 10 deletions(-) rename LICENSE.txt => LICENSE (80%) create mode 100644 cmake/config.cmake.in create mode 100644 cmake/install.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 353be44..7847632 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,22 @@ cmake_minimum_required(VERSION 3.14...3.28) -project(GKlib LANGUAGES C) + +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) +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} Arch: ${CMAKE_SYSTEM_PROCESSOR}") +message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION} Arch: ${CMAKE_SYSTEM_PROCESSOR} install prefix: ${CMAKE_INSTALL_PREFIX}") set(GKLIB_PATH ${PROJECT_SOURCE_DIR}) @@ -33,9 +41,18 @@ $<$:m> $<$:OpenMP::OpenMP_C> ) +add_library(GKlib::GKlib INTERFACE IMPORTED GLOBAL) +target_link_libraries(GKlib::GKlib INTERFACE GKlib) + if(BUILD_TESTING) add_subdirectory(test) endif() -install(TARGETS GKlib) -install(FILES ${GKlib_includes} TYPE INCLUDE) +install(TARGETS GKlib EXPORT ${PROJECT_NAME}-targets) + +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") + +include(cmake/install.cmake) diff --git a/LICENSE.txt b/LICENSE similarity index 80% rename from LICENSE.txt rename to LICENSE index b61ca6f..e8d9d95 100644 --- a/LICENSE.txt +++ b/LICENSE @@ -12,7 +12,6 @@ http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the License for the specific language governing +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied. See the License for the specific language governing permissions and limitations under the License. - diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in new file mode 100644 index 0000000..bf9065f --- /dev/null +++ b/cmake/config.cmake.in @@ -0,0 +1,9 @@ +@PACKAGE_INIT@ + +include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake) + +set(ffilesystem_shaky @ffilesystem_shaky@) + +target_link_libraries(metis::metis INTERFACE GKlib) + +check_required_components(@PROJECT_NAME@) diff --git a/cmake/install.cmake b/cmake/install.cmake new file mode 100644 index 0000000..b4f3197 --- /dev/null +++ b/cmake/install.cmake @@ -0,0 +1,50 @@ +# --- BOILERPLATE: install / packaging + +include(CMakePackageConfigHelpers) + +configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/config.cmake.in +${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake +INSTALL_DESTINATION cmake +) + +write_basic_package_version_file( +${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake +COMPATIBILITY SameMajorVersion +) + +install(EXPORT ${PROJECT_NAME}-targets +NAMESPACE ${PROJECT_NAME}:: +DESTINATION cmake +) + +install(FILES +${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake +${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake +DESTINATION cmake +) + +# # allow use of package from build directory without installing +export(EXPORT ${PROJECT_NAME}-targets +FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-targets.cmake +NAMESPACE ${PROJECT_NAME}:: +) + +# --- CPack + +set(CPACK_GENERATOR "TBZ2") +set(CPACK_SOURCE_GENERATOR "TBZ2") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +set(CPACK_PACKAGE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/package) + +# not .gitignore as its regex syntax is more advanced than CMake +set(CPACK_SOURCE_IGNORE_FILES .git/ .github/ .vscode/ _CPack_Packages/ +${CMAKE_BINARY_DIR}/ ${PROJECT_BINARY_DIR}/ +archive/ concepts/ +) + +install(FILES ${CPACK_RESOURCE_FILE_README} ${CPACK_RESOURCE_FILE_LICENSE} +DESTINATION share/docs/${PROJECT_NAME} +) + +include(CPack) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5cc05ed..164ebf5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,6 +17,3 @@ foreach(prog IN ITEMS strings gksort fis gkrw gkgraph csrcnv grKx m2mnbrs cmpnbr add_test(NAME ${prog} COMMAND ${prog}) endif() endforeach() - -# Install a subset of them -install(TARGETS csrcnv) From 2bf5cb41d04fc0daedf3e2533ce9e94de7ebd36d Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 7 Aug 2025 22:41:01 -0400 Subject: [PATCH 08/10] do not use -Werror --- GKlibSystem.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GKlibSystem.cmake b/GKlibSystem.cmake index 3081ec9..3c896cc 100644 --- a/GKlibSystem.cmake +++ b/GKlibSystem.cmake @@ -23,7 +23,7 @@ if(CYGWIN) endif() if(CMAKE_C_COMPILER_ID STREQUAL "GNU") - list(APPEND GKlib_COPTS -fno-strict-aliasing -Werror -Wall -pedantic -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unknown-pragmas -Wno-unused-label) + 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() if(UNIX) From 8770e9ef23458a4b6dc6431459ebdccfc917cb80 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 7 Aug 2025 23:04:14 -0400 Subject: [PATCH 09/10] don't build tests by default --- .github/workflows/ci.yml | 16 ++++++++++++---- CMakeLists.txt | 14 ++++++++++---- CMakePresets.json | 36 +----------------------------------- cmake/config.cmake.in | 4 ---- 4 files changed, 23 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d5fe99..81caa95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,13 @@ on: - "**.cmake" - "**/CMakeLists.txt" - ".github/workflows/ci.yml" + workflow_dispatch: + +# avoid wasted runs +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: @@ -20,15 +27,16 @@ jobs: timeout-minutes: 5 steps: - - uses: actions/checkout@v4 + - &checkout + uses: actions/checkout@v4 - - run: cmake --workflow --preset default + - run: cmake --workflow default windows_msvc: runs-on: windows-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v4 + - *checkout - - run: cmake --workflow --preset msvc + - run: cmake --workflow release diff --git a/CMakeLists.txt b/CMakeLists.txt index 7847632..07a181d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,8 @@ -cmake_minimum_required(VERSION 3.14...3.28) +cmake_minimum_required(VERSION 3.16...4.1) + +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 @@ -6,9 +10,11 @@ VERSION 1.0.0 enable_testing() -option(BUILD_TESTING "Build tests" ON) +include(GNUInstallDirs) + +option(BUILD_TESTING "Build tests") -option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF) +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) @@ -34,7 +40,7 @@ error.c gk_util.c itemsets.c rw.c tokenizer.c) add_library(GKlib ${GKlib_sources} ${win32_sources}) target_include_directories(GKlib PUBLIC $ -$ +$ ) target_link_libraries(GKlib PRIVATE $<$:m> diff --git a/CMakePresets.json b/CMakePresets.json index cd2d240..eac26dd 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -6,14 +6,7 @@ "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 + "BUILD_TESTING": true } } ], @@ -26,11 +19,6 @@ "name": "release", "configurePreset": "default", "configuration": "Release" - }, - { - "name": "msvc-debug", - "configurePreset": "msvc", - "configuration": "Debug" } ], "testPresets": [ @@ -51,11 +39,6 @@ { "name": "release", "inherits": "default", "configuration": "Release" -}, -{ - "name": "msvc-debug", "inherits": "default", - "configurePreset": "msvc", - "configuration": "Debug" } ], "workflowPresets": [ @@ -76,23 +59,6 @@ } ] }, - { - "name": "msvc", - "steps": [ - { - "type": "configure", - "name": "msvc" - }, - { - "type": "build", - "name": "msvc-debug" - }, - { - "type": "test", - "name": "msvc-debug" - } - ] - }, { "name": "release", "steps": [ diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index bf9065f..cfd7570 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -2,8 +2,4 @@ include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake) -set(ffilesystem_shaky @ffilesystem_shaky@) - -target_link_libraries(metis::metis INTERFACE GKlib) - check_required_components(@PROJECT_NAME@) From 2a1c94b1eec6da5eb1a4bd4415606731e81415ff Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 8 Aug 2025 04:37:50 -0400 Subject: [PATCH 10/10] MSVC compatible --- GKlibSystem.cmake | 5 +---- io.c | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/GKlibSystem.cmake b/GKlibSystem.cmake index 3c896cc..d652efb 100644 --- a/GKlibSystem.cmake +++ b/GKlibSystem.cmake @@ -71,10 +71,7 @@ endif(HAVE_GETLINE) # Custom check for TLS. if(MSVC) - list(APPEND GKlib_COPTIONS __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} diff --git a/io.c b/io.c index 289b401..508c4a4 100644 --- a/io.c +++ b/io.c @@ -16,6 +16,10 @@ This file contains various functions that perform I/O. #undef _GNU_SOURCE #endif +#ifdef _MSC_VER +#include +#endif + #include /************************************************************************* @@ -48,7 +52,7 @@ void gk_fclose(FILE *fp) /*************************************************************************/ -/*! This function is a wrapper around the read() function that ensures +/*! This function is a wrapper around the read() function that ensures that all data is been read, by issuing multiple read requests. The only time when not 'count' items are read is when the EOF has been reached. @@ -71,7 +75,7 @@ ssize_t gk_read(int fd, void *vbuf, size_t count) /*************************************************************************/ -/*! This function is a wrapper around the write() function that ensures +/*! This function is a wrapper around the write() function that ensures that all data is been written, by issueing multiple write requests. */ /*************************************************************************/ @@ -94,7 +98,7 @@ ssize_t gk_write(int fd, void *vbuf, size_t count) /*************************************************************************/ /*! This function is the GKlib implementation of glibc's getline() function. - \returns -1 if the EOF has been reached, otherwise it returns the + \returns -1 if the EOF has been reached, otherwise it returns the number of bytes read. */ /*************************************************************************/ @@ -107,7 +111,7 @@ ssize_t gk_getline(char **lineptr, size_t *n, FILE *stream) int ch; if (feof(stream)) - return -1; + return -1; /* Initial memory allocation if *lineptr is NULL */ if (*lineptr == NULL || *n == 0) { @@ -121,11 +125,11 @@ ssize_t gk_getline(char **lineptr, size_t *n, FILE *stream) (*lineptr)[i++] = (char)ch; /* reallocate memory if reached at the end of the buffer. The +1 is for '\0' */ - if (i+1 == *n) { + if (i+1 == *n) { *n = 2*(*n); *lineptr = gk_realloc(*lineptr, (*n)*sizeof(char), "gk_getline: lineptr"); } - + if (ch == '\n') break; } @@ -377,7 +381,7 @@ int32_t *gk_i32readfilebin(char *fname, size_t *r_nelmnts) array = gk_i32malloc(nelmnts, "gk_i32readfilebin: array"); fpin = gk_fopen(fname, "rb", "gk_i32readfilebin"); - + if (fread(array, sizeof(int32_t), nelmnts, fpin) != nelmnts) { gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts); gk_free((void **)&array, LTERM); @@ -444,7 +448,7 @@ int64_t *gk_i64readfilebin(char *fname, size_t *r_nelmnts) array = gk_i64malloc(nelmnts, "gk_i64readfilebin: array"); fpin = gk_fopen(fname, "rb", "gk_i64readfilebin"); - + if (fread(array, sizeof(int64_t), nelmnts, fpin) != nelmnts) { gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts); gk_free((void **)&array, LTERM); @@ -511,7 +515,7 @@ ssize_t *gk_zreadfilebin(char *fname, size_t *r_nelmnts) array = gk_zmalloc(nelmnts, "gk_zreadfilebin: array"); fpin = gk_fopen(fname, "rb", "gk_zreadfilebin"); - + if (fread(array, sizeof(ssize_t), nelmnts, fpin) != nelmnts) { gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts); gk_free((void **)&array, LTERM); @@ -578,7 +582,7 @@ float *gk_freadfilebin(char *fname, size_t *r_nelmnts) array = gk_fmalloc(nelmnts, "gk_freadfilebin: array"); fpin = gk_fopen(fname, "rb", "gk_freadfilebin"); - + if (fread(array, sizeof(float), nelmnts, fpin) != nelmnts) { gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts); gk_free((void **)&array, LTERM); @@ -645,7 +649,7 @@ double *gk_dreadfilebin(char *fname, size_t *r_nelmnts) array = gk_dmalloc(nelmnts, "gk_dreadfilebin: array"); fpin = gk_fopen(fname, "rb", "gk_dreadfilebin"); - + if (fread(array, sizeof(double), nelmnts, fpin) != nelmnts) { gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts); gk_free((void **)&array, LTERM); @@ -678,4 +682,3 @@ size_t gk_dwritefilebin(char *fname, size_t n, double *a) return fsize; } -