From 652d2068c6a825df8c7981efb5d43d72f7a92638 Mon Sep 17 00:00:00 2001 From: Jeremy Iverson Date: Mon, 30 Nov 2020 17:12:21 -0600 Subject: [PATCH 1/3] Adds support for modern CMake The primary purpose of this commit is to incorporate modern CMake (>=3.1) best practices. As a result, a reorganization of the directory structure as well as a few minor code cleanups was required. A summary of those changes follows: * Moves all header files into a separate include directory. * The test directory was renamed to apps, to allow for future unit tests to be written and included in a directory named test. * The win32 shims should only be included when compiling in a Windows environment. Upstream checks this by testing the CMake variable `MSVC`. However, this commit uses generator expressions and the more general test of the CMake Platform ID being equal to `Windows`. * All options and other configurable behavior of the CMakeLists file is implemented using generator-expressions. * Makes the GKlib apps disabled by default if the GKlib library is not the top CMake project and enabled if it is. This way, when GKlib is a dependency of another project, the apps are not build by default. An option, GKLIB_BUILD_APPS, was added to allow projects depending on GKlib to also build the apps. * Moves feature availability checks from `GKlibSystem.cmake` to the main `CMakeLists.txt`. This is to separate concerns, `CMakeLists.txt` contains core CMake logic, while `GKlibSystem.cmake` contains common compiler options and the like, which are convenient defaults, but may not be appropriate for all user of the build system. --- CMakeLists.txt | 224 ++++++++++++++++-- GKlibConfig.cmake.in | 1 + GKlibSystem.cmake | 137 ----------- Makefile | 21 +- README.md | 84 ++++--- apps/CMakeLists.txt | 13 + {test => apps}/cmpnbrs.c | 0 {test => apps}/csrcnv.c | 0 {test => apps}/fis.c | 0 {test => apps}/gkgraph.c | 0 test/rw.c => apps/gkrw.c | 0 {test => apps}/gksort.c | 0 {test => apps}/gkuniq.c | 0 {test => apps}/grKx.c | 0 {test => apps}/m2mnbrs.c | 0 {test => apps}/splatt2svd.c | 0 {test => apps}/strings.c | 0 cmake/GKlibSystem.cmake | 37 +++ conf/check_thread_storage.c | 5 - GKlib.h => include/GKlib/GKlib.h | 0 gk_arch.h => include/GKlib/gk_arch.h | 0 gk_defs.h => include/GKlib/gk_defs.h | 0 gk_externs.h => include/GKlib/gk_externs.h | 0 gk_getopt.h => include/GKlib/gk_getopt.h | 0 gk_macros.h => include/GKlib/gk_macros.h | 0 gk_mkblas.h => include/GKlib/gk_mkblas.h | 0 gk_mkmemory.h => include/GKlib/gk_mkmemory.h | 0 gk_mkpqueue.h => include/GKlib/gk_mkpqueue.h | 0 .../GKlib/gk_mkpqueue2.h | 0 gk_mkrandom.h => include/GKlib/gk_mkrandom.h | 0 gk_mksort.h => include/GKlib/gk_mksort.h | 0 gk_mkutils.h => include/GKlib/gk_mkutils.h | 0 .../GKlib/gk_ms_inttypes.h | 2 +- gk_ms_stat.h => include/GKlib/gk_ms_stat.h | 0 .../GKlib/gk_ms_stdint.h | 0 gk_proto.h => include/GKlib/gk_proto.h | 0 gk_struct.h => include/GKlib/gk_struct.h | 0 gk_types.h => include/GKlib/gk_types.h | 0 gkregex.h => include/GKlib/gkregex.h | 0 {win32 => include/GKlib/win32}/adapt.h | 0 b64.c => src/b64.c | 0 blas.c => src/blas.c | 0 cache.c => src/cache.c | 0 csr.c => src/csr.c | 0 error.c => src/error.c | 0 evaluate.c => src/evaluate.c | 0 fkvkselect.c => src/fkvkselect.c | 0 fs.c => src/fs.c | 0 getopt.c => src/getopt.c | 0 gk_util.c => src/gk_util.c | 0 gkregex.c => src/gkregex.c | 0 graph.c => src/graph.c | 0 htable.c => src/htable.c | 0 io.c => src/io.c | 0 itemsets.c => src/itemsets.c | 0 mcore.c => src/mcore.c | 0 memory.c => src/memory.c | 0 pqueue.c => src/pqueue.c | 0 random.c => src/random.c | 0 rw.c => src/rw.c | 0 seq.c => src/seq.c | 0 sort.c => src/sort.c | 0 string.c => src/string.c | 0 timers.c => src/timers.c | 0 tokenizer.c => src/tokenizer.c | 0 {win32 => src/win32}/adapt.c | 2 +- test/CMakeLists.txt | 19 -- 67 files changed, 315 insertions(+), 230 deletions(-) create mode 100644 GKlibConfig.cmake.in delete mode 100644 GKlibSystem.cmake create mode 100644 apps/CMakeLists.txt rename {test => apps}/cmpnbrs.c (100%) rename {test => apps}/csrcnv.c (100%) rename {test => apps}/fis.c (100%) rename {test => apps}/gkgraph.c (100%) rename test/rw.c => apps/gkrw.c (100%) rename {test => apps}/gksort.c (100%) rename {test => apps}/gkuniq.c (100%) rename {test => apps}/grKx.c (100%) rename {test => apps}/m2mnbrs.c (100%) rename {test => apps}/splatt2svd.c (100%) rename {test => apps}/strings.c (100%) create mode 100644 cmake/GKlibSystem.cmake delete mode 100644 conf/check_thread_storage.c rename GKlib.h => include/GKlib/GKlib.h (100%) rename gk_arch.h => include/GKlib/gk_arch.h (100%) rename gk_defs.h => include/GKlib/gk_defs.h (100%) rename gk_externs.h => include/GKlib/gk_externs.h (100%) rename gk_getopt.h => include/GKlib/gk_getopt.h (100%) rename gk_macros.h => include/GKlib/gk_macros.h (100%) rename gk_mkblas.h => include/GKlib/gk_mkblas.h (100%) rename gk_mkmemory.h => include/GKlib/gk_mkmemory.h (100%) rename gk_mkpqueue.h => include/GKlib/gk_mkpqueue.h (100%) rename gk_mkpqueue2.h => include/GKlib/gk_mkpqueue2.h (100%) rename gk_mkrandom.h => include/GKlib/gk_mkrandom.h (100%) rename gk_mksort.h => include/GKlib/gk_mksort.h (100%) rename gk_mkutils.h => include/GKlib/gk_mkutils.h (100%) rename gk_ms_inttypes.h => include/GKlib/gk_ms_inttypes.h (99%) rename gk_ms_stat.h => include/GKlib/gk_ms_stat.h (100%) rename gk_ms_stdint.h => include/GKlib/gk_ms_stdint.h (100%) rename gk_proto.h => include/GKlib/gk_proto.h (100%) rename gk_struct.h => include/GKlib/gk_struct.h (100%) rename gk_types.h => include/GKlib/gk_types.h (100%) rename gkregex.h => include/GKlib/gkregex.h (100%) rename {win32 => include/GKlib/win32}/adapt.h (100%) rename b64.c => src/b64.c (100%) rename blas.c => src/blas.c (100%) rename cache.c => src/cache.c (100%) rename csr.c => src/csr.c (100%) rename error.c => src/error.c (100%) rename evaluate.c => src/evaluate.c (100%) rename fkvkselect.c => src/fkvkselect.c (100%) rename fs.c => src/fs.c (100%) rename getopt.c => src/getopt.c (100%) rename gk_util.c => src/gk_util.c (100%) rename gkregex.c => src/gkregex.c (100%) rename graph.c => src/graph.c (100%) rename htable.c => src/htable.c (100%) rename io.c => src/io.c (100%) rename itemsets.c => src/itemsets.c (100%) rename mcore.c => src/mcore.c (100%) rename memory.c => src/memory.c (100%) rename pqueue.c => src/pqueue.c (100%) rename random.c => src/random.c (100%) rename rw.c => src/rw.c (100%) rename seq.c => src/seq.c (100%) rename sort.c => src/sort.c (100%) rename string.c => src/string.c (100%) rename timers.c => src/timers.c (100%) rename tokenizer.c => src/tokenizer.c (100%) rename {win32 => src/win32}/adapt.c (85%) delete mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cd1b4b..e545941 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,207 @@ -cmake_minimum_required(VERSION 2.8) -project(GKlib C) +cmake_minimum_required(VERSION 3.1) -option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF) +# ... +project(GKlib + VERSION 0.0.1 + LANGUAGES C) -get_filename_component(abs "." ABSOLUTE) -set(GKLIB_PATH ${abs}) -unset(abs) -include(GKlibSystem.cmake) +# include required CMake modules +include(CheckCCompilerFlag) +include(CheckCSourceCompiles) +include(CheckFunctionExists) +include(CheckIncludeFile) +include(CMakePackageConfigHelpers) +include(GNUInstallDirs) -include_directories(".") -if(MSVC) - include_directories("win32") - file(GLOB win32_sources RELATIVE "win32" "*.c") -else(MSVC) - set(win32_sources, "") -endif(MSVC) +#------------------------------------------------------------------------------- +# OPTIONS +#------------------------------------------------------------------------------- +option(ASSERT "turn asserts on" OFF) +option(ASSERT2 "additional assertions" OFF) +option(DEBUG "add debugging support" OFF) +option(GPROF "add gprof support" OFF) +option(GKRAND "enable GKRAND support" OFF) +option(GKREGEX "enable GKREGEX support" OFF) +option(OPENMP "enable OpenMP support" OFF) +option(PCRE "enable PCRE support" OFF) -add_library(GKlib ${GKlib_sources} ${win32_sources}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + option(GKLIB_BUILD_APPS "build the GKlib applications" ON) +else() + option(GKLIB_BUILD_APPS "build the GKlib applications" OFF) +endif() -if(UNIX) - target_link_libraries(GKlib m) -endif(UNIX) +#------------------------------------------------------------------------------- +# LIBRARY configuration +#------------------------------------------------------------------------------- +add_library(${PROJECT_NAME}) -include_directories("test") -add_subdirectory("test") +target_sources(${PROJECT_NAME} + PRIVATE src/b64.c src/blas.c src/cache.c src/csr.c src/error.c src/evaluate.c + src/fkvkselect.c src/fs.c src/getopt.c src/gk_util.c src/gkregex.c + src/graph.c src/htable.c src/io.c src/itemsets.c src/mcore.c + src/memory.c src/pqueue.c src/random.c src/rw.c src/seq.c src/sort.c + src/string.c src/timers.c src/tokenizer.c + # these are only included below so that they appear when using IDEs + include/GKlib/GKlib.h include/GKlib/gk_arch.h include/GKlib/gk_defs.h + include/GKlib/gk_externs.h include/GKlib/gk_getopt.h + include/GKlib/gk_macros.h include/GKlib/gk_mkblas.h + include/GKlib/gk_mkmemory.h include/GKlib/gk_mkpqueue.h + include/GKlib/gk_mkpqueue2.h include/GKlib/gk_mkrandom.h + include/GKlib/gk_mksort.h include/GKlib/gk_mkutils.h + include/GKlib/gk_proto.h include/GKlib/gk_struct.h + include/GKlib/gk_types.h include/GKlib/gkregex.h + include/GKlib/gk_ms_inttypes.h include/GKlib/gk_ms_stat.h + include/GKlib/gk_ms_stdint.h + # the following are shims for win32 systems + $<$:src/win32/adapt.c + include/GKlib/win32/adapt.h>) -install(TARGETS GKlib - ARCHIVE DESTINATION lib/${LINSTALL_PATH} - LIBRARY DESTINATION lib/${LINSTALL_PATH}) -install(FILES ${GKlib_includes} DESTINATION include/${HINSTALL_PATH}) +target_compile_definitions(${PROJECT_NAME} + PUBLIC $<$:LINUX>) + +target_include_directories(${PROJECT_NAME} + PUBLIC $ + $) + +target_link_libraries(${PROJECT_NAME} + PUBLIC $<$>:m>) + +set_target_properties(${PROJECT_NAME} PROPERTIES + SOVERSION ${PROJECT_VERSION_MAJOR} + VERSION ${PROJECT_VERSION}) + +add_library(GKlib::GKlib ALIAS ${PROJECT_NAME}) + +#------------------------------------------------------------------------------- +# OPTIONS configuration +#------------------------------------------------------------------------------- +target_compile_definitions(${PROJECT_NAME} + PUBLIC $<$>:NDEBUG> + $<$>:NDEBUG2> + $<$:DEBUG> + $<$:GKRAND>) + +#------------------------------------------------------------------------------- +# FEATURE AVAILABILITY checks +#------------------------------------------------------------------------------- +check_include_file(execinfo.h HAVE_EXECINFO_H) +check_function_exists(getline HAVE_GETLINE) + +# regular expressions +if(PCRE) + check_include_file(pcreposix.h HAVE_PCREPOSIX_H) + if(NOT HAVE_PCREPOSIX_H) + message(WARNING "PCRE was requested, but is not available") + endif() +endif() +if(NOT HAVE_PCREPOSIX_H) + check_include_file(regex.h HAVE_REGEX_H) + if(NOT HAVE_REGEX_H) + set(USE_GKREGEX ON) + endif() +endif() + +# profiling support +if(GPROF) + check_c_compiler_flag("-pg" HAVE_GPROF_SUPPORT) + if(NOT HAVE_GPROF_SUPPORT) + message(WARNING "GPROF support was requested, but is not available") + endif() +endif() + +# openmp support +if(OPENMP) + find_package(OpenMP) + if(NOT OpenMP_C_FOUND) + message(WARNING "OpenMP was requested, but is not available") + endif() +endif() + +# thread local storage +if(NOT DEFINED HAVE_TLS) + set(TLS_NAME "" CACHE INTERNAL "Thread local keyword") + foreach(tls_name "__thread" "__declspec(thread)") + unset(HAVE_TLS CACHE) + check_c_source_compiles("${tls_name} int x; int main(void) { return 0; }" + HAVE_TLS) + if (HAVE_TLS) + set(TLS_NAME ${tls_name} CACHE INTERNAL "Thread local keyword") + break() + else() + endif() + endforeach() +endif() + +target_compile_definitions(${PROJECT_NAME} + PUBLIC $<$:HAVE_EXEC_INFO_H> + $<$:USE_PCRE> + $<$,$>:HAVE_PCREPOSIX_H> + $<$:HAVE_REGEX_H> + $<$:USE_GKREGEX> + $<$:HAVE_GETLINE> + __thread=${TLS_NAME}) + +target_compile_options(${PROJECT_NAME} + PUBLIC $<$,$>:-pg>) + +target_link_libraries(${PROJECT_NAME} + PUBLIC $<$:OpenMP::OpenMP_C>) + +#------------------------------------------------------------------------------- +# APPS configuration +#------------------------------------------------------------------------------- +if(GKLIB_BUILD_APPS) + add_subdirectory("apps") +endif() + +#------------------------------------------------------------------------------- +# PACKAGE configuration +#------------------------------------------------------------------------------- +# generate files +configure_package_config_file(GKlibConfig.cmake.in cmake/GKlibConfig.cmake + INSTALL_DESTINATION lib/cmake/GKlib) + +write_basic_package_version_file(cmake/GKlibConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) + +# install library +install(TARGETS ${PROJECT_NAME} EXPORT GKlibTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT GKlib_Runtime + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT GKlib_Runtime + NAMELINK_SKIP + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT GKlib_Development + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +# The previous install() command is repeated here to distinguish installations +# that include a namelink versus those that do not. Unfortunately, prior to +# CMake 3.12, when the NAMELINK_COMPONENT property was introduced, this was +# necessary to get the desired behavior. +if(BUILD_SHARED_LIBS) + install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT GKlib_Development + NAMELINK_ONLY) +endif() + +# install header files +install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT GKlib_Development) + +# install files necessary to use find_package() with GKlib +install(EXPORT GKlibTargets + FILE GKlibTargets.cmake + NAMESPACE GKlib:: + DESTINATION lib/cmake/GKlib + COMPONENT GKlib_Development) + +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/GKlibConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/GKlibConfigVersion.cmake + DESTINATION lib/cmake/GKlib + COMPONENT GKlib_Development) diff --git a/GKlibConfig.cmake.in b/GKlibConfig.cmake.in new file mode 100644 index 0000000..a37fbd0 --- /dev/null +++ b/GKlibConfig.cmake.in @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/GKlibTargets.cmake) diff --git a/GKlibSystem.cmake b/GKlibSystem.cmake deleted file mode 100644 index d83b208..0000000 --- a/GKlibSystem.cmake +++ /dev/null @@ -1,137 +0,0 @@ -# Helper modules. -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(OPENMP "enable OpenMP support" OFF) -option(PCRE "enable PCRE support" OFF) -option(GKREGEX "enable GKREGEX support" OFF) -option(GKRAND "enable GKRAND 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") -else() - set(GKlib_COPTIONS "-DLINUX -D_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") - set(GKlib_COPTIONS "${GKlib_COPTIONS} -march=native") - 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") -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) - - -# 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) - - -# Add various options -if(PCRE) - set(GKlib_COPTIONS "${GKlib_COPTIONS} -D__WITHPCRE__") -endif(PCRE) - -if(GKREGEX) - set(GKlib_COPTIONS "${GKlib_COPTIONS} -DUSE_GKREGEX") -endif(GKREGEX) - -if(GKRAND) - set(GKlib_COPTIONS "${GKlib_COPTIONS} -DUSE_GKRAND") -endif(GKRAND) - - -# Check for features. -check_include_file(execinfo.h HAVE_EXECINFO_H) -if(HAVE_EXECINFO_H) - set(GKlib_COPTIONS "${GKlib_COPTIONS} -DHAVE_EXECINFO_H") -endif(HAVE_EXECINFO_H) - -check_function_exists(getline HAVE_GETLINE) -if(HAVE_GETLINE) - set(GKlib_COPTIONS "${GKlib_COPTIONS} -DHAVE_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}$") - 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") - else() - message(STATUS "checking for thread-local storage - not found") - endif() - endif() - if(NOT HAVE_THREADLOCALSTORAGE) - set(GKlib_COPTIONS "${GKlib_COPTIONS} -D__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) diff --git a/Makefile b/Makefile index c9543d4..872518f 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ # Configuration options. -cc = gcc +cc = $(CC) prefix = ~/local openmp = not-set -gdb = not-set assert = not-set assert2 = not-set debug = not-set @@ -11,7 +10,6 @@ pcre = not-set gkregex = not-set gkrand = not-set - # Basically proxies everything to the builddir cmake. cputype = $(shell uname -m | sed "s/\\ /_/g") systype = $(shell uname -s) @@ -19,10 +17,8 @@ systype = $(shell uname -s) BUILDDIR = build/$(systype)-$(cputype) # Process configuration options. -CONFIG_FLAGS = -DCMAKE_VERBOSE_MAKEFILE=1 -ifneq ($(gdb), not-set) - CONFIG_FLAGS += -DGDB=$(gdb) -endif +CONFIG_FLAGS = +BUILD_FLAGS = ifneq ($(assert), not-set) CONFIG_FLAGS += -DASSERT=$(assert) endif @@ -42,21 +38,20 @@ ifneq ($(pcre), not-set) CONFIG_FLAGS += -DPCRE=$(pcre) endif ifneq ($(gkregex), not-set) - CONFIG_FLAGS += -DGKREGEX=$(pcre) + CONFIG_FLAGS += -DGKREGEX=$(gkregex) endif ifneq ($(gkrand), not-set) - CONFIG_FLAGS += -DGKRAND=$(pcre) + CONFIG_FLAGS += -DGKRAND=$(gkrand) endif ifneq ($(prefix), not-set) CONFIG_FLAGS += -DCMAKE_INSTALL_PREFIX=$(prefix) endif -ifneq ($(cc), not-set) - CONFIG_FLAGS += -DCMAKE_C_COMPILER=$(cc) -endif +# Include GKlibSystem.cmake by default +CONFIG_FLAGS += -DGKLIB_SYSTEM=./cmake/GKlibSystem.cmake define run-config mkdir -p $(BUILDDIR) -cd $(BUILDDIR) && cmake $(CURDIR) $(CONFIG_FLAGS) +cd $(BUILDDIR) && CC=$(cc) cmake $(CURDIR) $(CONFIG_FLAGS) endef all clean install: $(BUILDDIR) diff --git a/README.md b/README.md index f94eeea..8ab1923 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,78 @@ # GKlib -A library of various helper routines and frameworks used by many of the lab's software +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. + - CMake 3.1, found at http://www.cmake.org/, as well as GNU make or some other + build system supported by CMake. -Assuming that the above are available, two commands should suffice to -build the software: +Assuming that the above are available, the following sequence of commands should +suffice to build the software on a Unix-like system: ``` -make config -make +mkdir build && cd build +cmake .. +cmake --build . ``` ## Configuring the build -It is primarily configured by passing options to make config. For example: +The build is primarily configured by passing options to CMake or setting +environment variables prior to invoking CMake. For example: ``` -make config cc=icc +CC=icc cmake .. ``` -would configure it to be built using icc. +would configure it to be built using icc. While -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 +cmake -DOPENMP=ON -DCMAKE_BUILD_TYPE=Release .. ``` +would configure it to be build using the default compiler, with OpenMP if +available, and in release mode (aggressive optimizations enabled). + +To see a list of options that can be set using the `-D...` syntax, run -## Building and installing -To build and install, run the following ``` -make -make install +cmake -L . ``` -By default, the library file, header file, and binaries will be installed in +from the build directory. To see relevant environment variables, visit +https://cmake.org/cmake/help/latest/manual/cmake-env-variables.7.html. + +## Customizing the build +In addition to the standard CMake configurations, there is also the CMake +variable, `CMAKE_PROJECT_GKlib_INCLUDE`. When this variable is defined, it +should give the path to a CMake script where compiler options and the like can +be specified. This allows the user of the build system to have a file where +common CMake settings can be managed without modifying the core CMake logic. For +example, CMake could be configured using the script, `GKlibSystem.cmake` +provided in the `cmake` directory like so: + ``` -~/local/lib -~/local/include -~/local/bin +-DCMAKE_PROJECT_GKlib_INCLUDE=cmake/GKlibSystem.cmake ``` -## 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. +The path to the file should be relative to the directory containing the +top-level `CMakeLists.txt` file. +## Installing +Installing will depend on the generator used by CMake. For builds using the +Makefile generator, the following command will suffice: +``` +make install +``` +By default, the library file, header files, and some useful applications will be +installed in standard GNU install directories. This too however can be +configured via options. For example: +``` +cmake -DCMAKE_INSTALL_PREFIX=~/local .. +``` + +during configuration will install said files to the following directories +respectively: + +``` +~/local/lib +~/local/include/GKlib +``` diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt new file mode 100644 index 0000000..6c47641 --- /dev/null +++ b/apps/CMakeLists.txt @@ -0,0 +1,13 @@ +# Build programs. +set(GKLIB_PROGRAMS strings gksort fis gkrw gkgraph csrcnv grKx m2mnbrs cmpnbrs + splatt2svd gkuniq) + +foreach(prog ${GKLIB_PROGRAMS}) + add_executable(${prog} ${prog}.c) + target_link_libraries(${prog} GKlib::GKlib) +endforeach() + +# install executables +install(TARGETS csrcnv + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT GKlib_Applications) diff --git a/test/cmpnbrs.c b/apps/cmpnbrs.c similarity index 100% rename from test/cmpnbrs.c rename to apps/cmpnbrs.c diff --git a/test/csrcnv.c b/apps/csrcnv.c similarity index 100% rename from test/csrcnv.c rename to apps/csrcnv.c diff --git a/test/fis.c b/apps/fis.c similarity index 100% rename from test/fis.c rename to apps/fis.c diff --git a/test/gkgraph.c b/apps/gkgraph.c similarity index 100% rename from test/gkgraph.c rename to apps/gkgraph.c diff --git a/test/rw.c b/apps/gkrw.c similarity index 100% rename from test/rw.c rename to apps/gkrw.c diff --git a/test/gksort.c b/apps/gksort.c similarity index 100% rename from test/gksort.c rename to apps/gksort.c diff --git a/test/gkuniq.c b/apps/gkuniq.c similarity index 100% rename from test/gkuniq.c rename to apps/gkuniq.c diff --git a/test/grKx.c b/apps/grKx.c similarity index 100% rename from test/grKx.c rename to apps/grKx.c diff --git a/test/m2mnbrs.c b/apps/m2mnbrs.c similarity index 100% rename from test/m2mnbrs.c rename to apps/m2mnbrs.c diff --git a/test/splatt2svd.c b/apps/splatt2svd.c similarity index 100% rename from test/splatt2svd.c rename to apps/splatt2svd.c diff --git a/test/strings.c b/apps/strings.c similarity index 100% rename from test/strings.c rename to apps/strings.c diff --git a/cmake/GKlibSystem.cmake b/cmake/GKlibSystem.cmake new file mode 100644 index 0000000..6965c57 --- /dev/null +++ b/cmake/GKlibSystem.cmake @@ -0,0 +1,37 @@ +# Helper modules. + +# 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") +else() + set(GKlib_COPTIONS "-DLINUX -D_FILE_OFFSET_BITS=64") +endif() +if(CYGWIN) + set(GKlib_COPTIONS "${GKlib_COPTIONS} -DCYGWIN") +endif() +if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") +# GCC opts. + set(GKlib_COPTIONS "${GKlib_COPTIONS} -std=c99 -fno-strict-aliasing") + set(GKlib_COPTIONS "${GKlib_COPTIONS} -march=native") + if(NOT MINGW) + set(GKlib_COPTIONS "${GKlib_COPTIONS} -fPIC") + endif() +# GCC warnings. + set(GKlib_COPTIONS "${GKlib_COPTIONS} -Werror -Wall -pedantic -Wno-unused-function -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") +else() + message("NO COMIPLER ID") +endif() + +# Intel compiler +if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") + set(GKlib_COPTIONS "${GKlib_COPTIONS} -xHost -std=c99") +endif() + +# Finally set the official C flags. +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GKlib_COPTIONS} ${GKlib_COPTS}") diff --git a/conf/check_thread_storage.c b/conf/check_thread_storage.c deleted file mode 100644 index e6e1e98..0000000 --- a/conf/check_thread_storage.c +++ /dev/null @@ -1,5 +0,0 @@ -extern __thread int x; - -int main(int argc, char **argv) { - return 0; -} diff --git a/GKlib.h b/include/GKlib/GKlib.h similarity index 100% rename from GKlib.h rename to include/GKlib/GKlib.h diff --git a/gk_arch.h b/include/GKlib/gk_arch.h similarity index 100% rename from gk_arch.h rename to include/GKlib/gk_arch.h diff --git a/gk_defs.h b/include/GKlib/gk_defs.h similarity index 100% rename from gk_defs.h rename to include/GKlib/gk_defs.h diff --git a/gk_externs.h b/include/GKlib/gk_externs.h similarity index 100% rename from gk_externs.h rename to include/GKlib/gk_externs.h diff --git a/gk_getopt.h b/include/GKlib/gk_getopt.h similarity index 100% rename from gk_getopt.h rename to include/GKlib/gk_getopt.h diff --git a/gk_macros.h b/include/GKlib/gk_macros.h similarity index 100% rename from gk_macros.h rename to include/GKlib/gk_macros.h diff --git a/gk_mkblas.h b/include/GKlib/gk_mkblas.h similarity index 100% rename from gk_mkblas.h rename to include/GKlib/gk_mkblas.h diff --git a/gk_mkmemory.h b/include/GKlib/gk_mkmemory.h similarity index 100% rename from gk_mkmemory.h rename to include/GKlib/gk_mkmemory.h diff --git a/gk_mkpqueue.h b/include/GKlib/gk_mkpqueue.h similarity index 100% rename from gk_mkpqueue.h rename to include/GKlib/gk_mkpqueue.h diff --git a/gk_mkpqueue2.h b/include/GKlib/gk_mkpqueue2.h similarity index 100% rename from gk_mkpqueue2.h rename to include/GKlib/gk_mkpqueue2.h diff --git a/gk_mkrandom.h b/include/GKlib/gk_mkrandom.h similarity index 100% rename from gk_mkrandom.h rename to include/GKlib/gk_mkrandom.h diff --git a/gk_mksort.h b/include/GKlib/gk_mksort.h similarity index 100% rename from gk_mksort.h rename to include/GKlib/gk_mksort.h diff --git a/gk_mkutils.h b/include/GKlib/gk_mkutils.h similarity index 100% rename from gk_mkutils.h rename to include/GKlib/gk_mkutils.h diff --git a/gk_ms_inttypes.h b/include/GKlib/gk_ms_inttypes.h similarity index 99% rename from gk_ms_inttypes.h rename to include/GKlib/gk_ms_inttypes.h index e26204b..b89fc10 100644 --- a/gk_ms_inttypes.h +++ b/include/GKlib/gk_ms_inttypes.h @@ -40,7 +40,7 @@ #pragma once #endif -#include "ms_stdint.h" +#include "gk_ms_stdint.h" // 7.8 Format conversion of integer types diff --git a/gk_ms_stat.h b/include/GKlib/gk_ms_stat.h similarity index 100% rename from gk_ms_stat.h rename to include/GKlib/gk_ms_stat.h diff --git a/gk_ms_stdint.h b/include/GKlib/gk_ms_stdint.h similarity index 100% rename from gk_ms_stdint.h rename to include/GKlib/gk_ms_stdint.h diff --git a/gk_proto.h b/include/GKlib/gk_proto.h similarity index 100% rename from gk_proto.h rename to include/GKlib/gk_proto.h diff --git a/gk_struct.h b/include/GKlib/gk_struct.h similarity index 100% rename from gk_struct.h rename to include/GKlib/gk_struct.h diff --git a/gk_types.h b/include/GKlib/gk_types.h similarity index 100% rename from gk_types.h rename to include/GKlib/gk_types.h diff --git a/gkregex.h b/include/GKlib/gkregex.h similarity index 100% rename from gkregex.h rename to include/GKlib/gkregex.h diff --git a/win32/adapt.h b/include/GKlib/win32/adapt.h similarity index 100% rename from win32/adapt.h rename to include/GKlib/win32/adapt.h diff --git a/b64.c b/src/b64.c similarity index 100% rename from b64.c rename to src/b64.c diff --git a/blas.c b/src/blas.c similarity index 100% rename from blas.c rename to src/blas.c diff --git a/cache.c b/src/cache.c similarity index 100% rename from cache.c rename to src/cache.c diff --git a/csr.c b/src/csr.c similarity index 100% rename from csr.c rename to src/csr.c diff --git a/error.c b/src/error.c similarity index 100% rename from error.c rename to src/error.c diff --git a/evaluate.c b/src/evaluate.c similarity index 100% rename from evaluate.c rename to src/evaluate.c diff --git a/fkvkselect.c b/src/fkvkselect.c similarity index 100% rename from fkvkselect.c rename to src/fkvkselect.c diff --git a/fs.c b/src/fs.c similarity index 100% rename from fs.c rename to src/fs.c diff --git a/getopt.c b/src/getopt.c similarity index 100% rename from getopt.c rename to src/getopt.c diff --git a/gk_util.c b/src/gk_util.c similarity index 100% rename from gk_util.c rename to src/gk_util.c diff --git a/gkregex.c b/src/gkregex.c similarity index 100% rename from gkregex.c rename to src/gkregex.c diff --git a/graph.c b/src/graph.c similarity index 100% rename from graph.c rename to src/graph.c diff --git a/htable.c b/src/htable.c similarity index 100% rename from htable.c rename to src/htable.c diff --git a/io.c b/src/io.c similarity index 100% rename from io.c rename to src/io.c diff --git a/itemsets.c b/src/itemsets.c similarity index 100% rename from itemsets.c rename to src/itemsets.c diff --git a/mcore.c b/src/mcore.c similarity index 100% rename from mcore.c rename to src/mcore.c diff --git a/memory.c b/src/memory.c similarity index 100% rename from memory.c rename to src/memory.c diff --git a/pqueue.c b/src/pqueue.c similarity index 100% rename from pqueue.c rename to src/pqueue.c diff --git a/random.c b/src/random.c similarity index 100% rename from random.c rename to src/random.c diff --git a/rw.c b/src/rw.c similarity index 100% rename from rw.c rename to src/rw.c diff --git a/seq.c b/src/seq.c similarity index 100% rename from seq.c rename to src/seq.c diff --git a/sort.c b/src/sort.c similarity index 100% rename from sort.c rename to src/sort.c diff --git a/string.c b/src/string.c similarity index 100% rename from string.c rename to src/string.c diff --git a/timers.c b/src/timers.c similarity index 100% rename from timers.c rename to src/timers.c diff --git a/tokenizer.c b/src/tokenizer.c similarity index 100% rename from tokenizer.c rename to src/tokenizer.c diff --git a/win32/adapt.c b/src/win32/adapt.c similarity index 85% rename from win32/adapt.c rename to src/win32/adapt.c index 546857c..d56f767 100644 --- a/win32/adapt.c +++ b/src/win32/adapt.c @@ -3,7 +3,7 @@ \brief Implementation of Win32 adaptation of libc functions */ -#include "adapt.h" +#include "win32/adapt.h" pid_t getpid(void) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 8584820..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Build program. -add_executable(strings strings.c) -add_executable(gksort gksort.c) -add_executable(fis fis.c) -add_executable(gkrw rw.c) -add_executable(gkgraph gkgraph.c) -add_executable(csrcnv csrcnv.c) -add_executable(grKx grKx.c) -add_executable(m2mnbrs m2mnbrs.c) -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) - -# Install a subset of them -install(TARGETS csrcnv RUNTIME DESTINATION bin) From 26a94c310a413ef347820b24d38afde1584dc5d4 Mon Sep 17 00:00:00 2001 From: Jeremy Iverson Date: Mon, 30 Nov 2020 17:15:36 -0600 Subject: [PATCH 2/3] Adds support for Travis CI Adds support for testing successful compilation (w/ and w/o apps) on Travis using Linux, Windows, and Apple. --- .travis.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..369efcc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +# root key configurations (defaults). +dist: xenial + +# operating systems configurations. +os: + - linux + - osx + - windows + +# language configurations. +language: c + +# env variable to toggle apps on and off. +env: + - CMAKE_OPTS=-DGKLIB_BUILD_APPS=ON + - CMAKE_OPTS=-DGKLIB_BUILD_APPS=OFF + +# invalid configurations to be explicitly included. +jobs: + include: + - os: linux + compiler: clang + env: CMAKE_OPTS=-DGKLIB_BUILD_APPS=ON + - os: linux + compiler: clang + env: CMAKE_OPTS=-DGKLIB_BUILD_APPS=OFF + +# Override default script. +script: + - cmake ${CMAKE_OPTS} . && cmake --build . && ctest --output-on-failure From fd871216da9c0e123e2270f067e13814f7281ef8 Mon Sep 17 00:00:00 2001 From: Jeremy Iverson Date: Mon, 30 Nov 2020 18:19:20 -0600 Subject: [PATCH 3/3] Cleans up source This primary purpose of this commit is to make some minor changes to the code to clean it up a bit. Notable changes are as follows: * The macro `__OPENMP__` is replaced by `_OPENMP`. `__OPENMP__` was an artifact from the old build system, which defined such a macro when the build was configured with OpenMP support. According to the [OpenMP specification](https://www.openmp.org/specifications/) Section [2.2](https://www.openmp.org/spec-html/5.1/openmpse10.html#x38-370002.2) "the `_OPENMP` macro name is defined to have the decimal value *yyyymm* where *yyyy* and *mm* are the year and month designations of the version of the OpenMP API that the implementation supports." As such, it should be the preferred way to check for OpenMP support during compilation. * The preprocessor condition `defined(__WITHPCRE__)` is replaced by `defined(USE_PCRE) && defined(HAVE_PCREPOSIX_H)`. `__WITHPCRE__` was an artifact from the old build system, which was defined during configuration if the build system user requested PCRE support. This functionality has been replaced by the macro name `USE_PCRE` to be consistent with the other feature availability checks done in the core CMake logic and the condition has been extended to not only check for the request (`USE_PCRE`), but also the availability of the necessary header file, namely `pcreposix.h` indicated by the macro name `HAVE_PCREPOSIX_H` being defined during CMake configuration. --- apps/cmpnbrs.c | 2 +- apps/csrcnv.c | 2 +- apps/fis.c | 2 +- apps/gkgraph.c | 2 +- apps/gkrw.c | 2 +- apps/gksort.c | 2 +- apps/gkuniq.c | 2 +- apps/grKx.c | 2 +- apps/m2mnbrs.c | 2 +- apps/splatt2svd.c | 2 +- apps/strings.c | 2 +- include/GKlib/GKlib.h | 42 ++++++++++++++++++------------------- include/GKlib/gk_getopt.h | 16 +++++++------- include/GKlib/gk_mkpqueue.h | 3 +++ include/GKlib/gk_proto.h | 4 ++-- src/blas.c | 2 +- src/cache.c | 2 +- src/csr.c | 2 +- src/error.c | 2 +- src/evaluate.c | 2 +- src/fkvkselect.c | 2 +- src/fs.c | 2 +- src/getopt.c | 2 +- src/gk_util.c | 2 +- src/graph.c | 4 ++-- src/htable.c | 2 +- src/io.c | 2 +- src/itemsets.c | 2 +- src/mcore.c | 2 +- src/memory.c | 2 +- src/pqueue.c | 2 +- src/random.c | 2 +- src/rw.c | 2 +- src/seq.c | 2 +- src/sort.c | 2 +- src/string.c | 4 ++-- src/timers.c | 4 ++-- src/tokenizer.c | 2 +- 38 files changed, 70 insertions(+), 69 deletions(-) diff --git a/apps/cmpnbrs.c b/apps/cmpnbrs.c index 6e3ace8..64a88f0 100644 --- a/apps/cmpnbrs.c +++ b/apps/cmpnbrs.c @@ -9,7 +9,7 @@ \version \verbatim $Id: m2mnbrs.c 17699 2014-09-27 18:05:31Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ /*! Data structures for the code */ diff --git a/apps/csrcnv.c b/apps/csrcnv.c index aef808e..94ccabe 100644 --- a/apps/csrcnv.c +++ b/apps/csrcnv.c @@ -8,7 +8,7 @@ \version \verbatim $Id: csrcnv.c 15314 2013-10-05 16:50:50Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ /*! Data structures for the code */ diff --git a/apps/fis.c b/apps/fis.c index 084a4b6..387d6fc 100644 --- a/apps/fis.c +++ b/apps/fis.c @@ -7,7 +7,7 @@ \version \verbatim $Id: fis.c 11075 2011-11-11 22:31:52Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ /*! Data structures for the code */ diff --git a/apps/gkgraph.c b/apps/gkgraph.c index 9131464..1dabd0d 100644 --- a/apps/gkgraph.c +++ b/apps/gkgraph.c @@ -7,7 +7,7 @@ \version \verbatim $Id: gkgraph.c 17700 2014-09-27 18:10:02Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ diff --git a/apps/gkrw.c b/apps/gkrw.c index 1a3295e..dcc66ea 100644 --- a/apps/gkrw.c +++ b/apps/gkrw.c @@ -7,7 +7,7 @@ \version \verbatim $Id$ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ /*! Data structures for the code */ diff --git a/apps/gksort.c b/apps/gksort.c index 6543836..0ec38b7 100644 --- a/apps/gksort.c +++ b/apps/gksort.c @@ -7,7 +7,7 @@ \version\verbatim $Id: gksort.c 11058 2011-11-10 00:02:50Z karypis $ \endverbatim */ -#include +#include "GKlib.h" #define N 10000 diff --git a/apps/gkuniq.c b/apps/gkuniq.c index c30b0f7..3ee77a0 100644 --- a/apps/gkuniq.c +++ b/apps/gkuniq.c @@ -6,7 +6,7 @@ \author George */ -#include +#include "GKlib.h" /*************************************************************************/ /*! Data structures for the code */ diff --git a/apps/grKx.c b/apps/grKx.c index a72b580..f87d35c 100644 --- a/apps/grKx.c +++ b/apps/grKx.c @@ -7,7 +7,7 @@ \version \verbatim $Id: grKx.c 17699 2014-09-27 18:05:31Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ /*! Data structures for the code */ diff --git a/apps/m2mnbrs.c b/apps/m2mnbrs.c index 53f35ca..b6f7671 100644 --- a/apps/m2mnbrs.c +++ b/apps/m2mnbrs.c @@ -8,7 +8,7 @@ \version \verbatim $Id: m2mnbrs.c 17699 2014-09-27 18:05:31Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ /*! Data structures for the code */ diff --git a/apps/splatt2svd.c b/apps/splatt2svd.c index 111d31c..6078161 100644 --- a/apps/splatt2svd.c +++ b/apps/splatt2svd.c @@ -6,7 +6,7 @@ \author George */ -#include +#include "GKlib.h" int main(int argc, char *argv[]) diff --git a/apps/strings.c b/apps/strings.c index b241d3f..369d2a6 100644 --- a/apps/strings.c +++ b/apps/strings.c @@ -7,7 +7,7 @@ \version\verbatim $Id: strings.c 10711 2011-08-31 22:23:04Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ diff --git a/include/GKlib/GKlib.h b/include/GKlib/GKlib.h index 9278fe4..5ab6358 100644 --- a/include/GKlib/GKlib.h +++ b/include/GKlib/GKlib.h @@ -43,41 +43,39 @@ #include #include -#if defined(__WITHPCRE__) +#if defined(USE_PCRE) && defined(HAVE_PCREPOSIX_H) #include +#elif defined(HAVE_REGEX_H) + #include #else - #if defined(USE_GKREGEX) - #include "gkregex.h" - #else - #include - #endif /* defined(USE_GKREGEX) */ -#endif /* defined(__WITHPCRE__) */ + #include "gkregex.h" +#endif -#if defined(__OPENMP__) +#if defined(_OPENMP) #include #endif -#include -#include -#include -#include -#include -#include +#include "gk_types.h" +#include "gk_struct.h" +#include "gk_externs.h" +#include "gk_defs.h" +#include "gk_macros.h" +#include "gk_getopt.h" -#include -#include -#include -#include -#include -#include -#include +#include "gk_mksort.h" +#include "gk_mkblas.h" +#include "gk_mkmemory.h" +#include "gk_mkpqueue.h" +#include "gk_mkpqueue2.h" +#include "gk_mkrandom.h" +#include "gk_mkutils.h" -#include +#include "gk_proto.h" #endif /* GKlib.h */ diff --git a/include/GKlib/gk_getopt.h b/include/GKlib/gk_getopt.h index 4bb8611..99a9885 100644 --- a/include/GKlib/gk_getopt.h +++ b/include/GKlib/gk_getopt.h @@ -46,17 +46,17 @@ struct gk_option { }; /* Names for the values of the `has_arg' field of `struct gk_option'. */ -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 /* Function prototypes */ -extern int gk_getopt(int __argc, char **__argv, char *__shortopts); -extern int gk_getopt_long(int __argc, char **__argv, char *__shortopts, - struct gk_option *__longopts, int *__longind); -extern int gk_getopt_long_only (int __argc, char **__argv, - char *__shortopts, struct gk_option *__longopts, int *__longind); +extern int gk_getopt(int argc, char **argv, char *shortopts); +extern int gk_getopt_long(int argc, char **argv, char *shortopts, + struct gk_option *longopts, int *longind); +extern int gk_getopt_long_only (int argc, char **argv, + char *shortopts, struct gk_option *longopts, int *longind); diff --git a/include/GKlib/gk_mkpqueue.h b/include/GKlib/gk_mkpqueue.h index 50a5385..2055e0a 100644 --- a/include/GKlib/gk_mkpqueue.h +++ b/include/GKlib/gk_mkpqueue.h @@ -391,6 +391,9 @@ int FPRFX ## CheckHeap(PQT *queue)\ heap = queue->heap;\ locator = queue->locator;\ nnodes = queue->nnodes;\ +\ + /* silence unused-but-set-variable */\ + (void)heap;\ \ if (nnodes == 0)\ return 1;\ diff --git a/include/GKlib/gk_proto.h b/include/GKlib/gk_proto.h index 80a52f2..23d8103 100644 --- a/include/GKlib/gk_proto.h +++ b/include/GKlib/gk_proto.h @@ -289,7 +289,7 @@ uint32_t gk_randint32(void); /*------------------------------------------------------------- * OpenMP fake functions *-------------------------------------------------------------*/ -#if !defined(__OPENMP__) +#if !defined(_OPENMP) void omp_set_num_threads(int num_threads); int omp_get_num_threads(void); int omp_get_max_threads(void); @@ -300,7 +300,7 @@ void omp_set_dynamic(int num_threads); int omp_get_dynamic(void); void omp_set_nested(int nested); int omp_get_nested(void); -#endif /* __OPENMP__ */ +#endif /* _OPENMP */ /*------------------------------------------------------------- diff --git a/src/blas.c b/src/blas.c index a0b95ca..edf60de 100644 --- a/src/blas.c +++ b/src/blas.c @@ -15,7 +15,7 @@ which is used for code generation. \version\verbatim $Id: blas.c 14330 2013-05-18 12:15:15Z karypis $ \endverbatim */ -#include +#include "GKlib.h" diff --git a/src/cache.c b/src/cache.c index 932e36d..f7e46e9 100644 --- a/src/cache.c +++ b/src/cache.c @@ -9,7 +9,7 @@ \version $Id: cache.c 21991 2018-04-16 03:08:12Z karypis $ */ -#include +#include "GKlib.h" /*************************************************************************/ diff --git a/src/csr.c b/src/csr.c index 7e92a0c..ff29b46 100644 --- a/src/csr.c +++ b/src/csr.c @@ -7,7 +7,7 @@ * \version\verbatim $Id: csr.c 21044 2017-05-24 22:50:32Z karypis $ \endverbatim */ -#include +#include "GKlib.h" #define OMPMINOPS 50000 diff --git a/src/error.c b/src/error.c index e2a18cf..53aa550 100644 --- a/src/error.c +++ b/src/error.c @@ -13,7 +13,7 @@ This file contains functions dealing with error reporting and termination #define _GK_ERROR_C_ /* this is needed to properly declare the gk_jub* variables as an extern function in GKlib.h */ -#include +#include "GKlib.h" /* These are the jmp_buf for the graceful exit in case of severe errors. diff --git a/src/evaluate.c b/src/evaluate.c index ce805ce..f0be5b4 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -7,7 +7,7 @@ \version\verbatim $Id: evaluate.c 13328 2012-12-31 14:57:40Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /********************************************************************** * This function computes the max accuracy score of a ranked list, diff --git a/src/fkvkselect.c b/src/fkvkselect.c index b1238ce..a2cbac4 100644 --- a/src/fkvkselect.c +++ b/src/fkvkselect.c @@ -8,7 +8,7 @@ */ -#include +#include "GKlib.h" /* Byte-wise swap two items of size SIZE. */ #define QSSWAP(a, b, stmp) do { stmp = (a); (a) = (b); (b) = stmp; } while (0) diff --git a/src/fs.c b/src/fs.c index 21081dd..2444705 100644 --- a/src/fs.c +++ b/src/fs.c @@ -11,7 +11,7 @@ the filesystem in a portable way. */ -#include +#include "GKlib.h" diff --git a/src/getopt.c b/src/getopt.c index 2e7e042..cd5d664 100644 --- a/src/getopt.c +++ b/src/getopt.c @@ -34,7 +34,7 @@ So, do read the documentation here. /*************************************************************************/ -#include +#include "GKlib.h" /*************************************************************************/ /* Local function prototypes */ diff --git a/src/gk_util.c b/src/gk_util.c index e1e68db..82146c0 100644 --- a/src/gk_util.c +++ b/src/gk_util.c @@ -8,7 +8,7 @@ */ -#include +#include "GKlib.h" /************************************************************************* diff --git a/src/graph.c b/src/graph.c index 1bfd0cc..4b50e47 100644 --- a/src/graph.c +++ b/src/graph.c @@ -7,7 +7,7 @@ * \version\verbatim $Id: graph.c 22415 2019-09-05 16:55:00Z karypis $ \endverbatim */ -#include +#include "GKlib.h" #define OMPMINOPS 50000 @@ -294,7 +294,7 @@ gk_graph_t *gk_graph_Read(char *filename, int format, int hasvals, fpin = gk_fopen(filename, "r", "gk_graph_Read: fpin"); if (format == GK_GRAPH_FMT_HIJV) { /* read and ignore the #rows/#cols values */ - if (fscanf(fpin, "%"SCNd64" %"SCNd64, &i, &i) != 2) + if (fscanf(fpin, "%zu %zu", &i, &i) != 2) gk_errexit(SIGERR, "Error: Failed to read the header line.\n"); } diff --git a/src/htable.c b/src/htable.c index 078e114..666708f 100644 --- a/src/htable.c +++ b/src/htable.c @@ -8,7 +8,7 @@ * */ -#include +#include "GKlib.h" /****************************************************************************** * This function creates the hash-table diff --git a/src/io.c b/src/io.c index d8de779..398a381 100644 --- a/src/io.c +++ b/src/io.c @@ -16,7 +16,7 @@ This file contains various functions that perform I/O. #undef _GNU_SOURCE #endif -#include +#include "GKlib.h" /************************************************************************* * This function opens a file diff --git a/src/itemsets.c b/src/itemsets.c index beb58ae..4eb13b2 100644 --- a/src/itemsets.c +++ b/src/itemsets.c @@ -10,7 +10,7 @@ * \version\verbatim $Id: itemsets.c 19240 2015-10-22 12:41:19Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*-------------------------------------------------------------*/ /*! Data structures for use within this module */ diff --git a/src/mcore.c b/src/mcore.c index 6442e03..d76e4b1 100644 --- a/src/mcore.c +++ b/src/mcore.c @@ -8,7 +8,7 @@ \version $Id: mcore.c 13953 2013-03-30 16:20:07Z karypis $ */ -#include +#include "GKlib.h" /*************************************************************************/ diff --git a/src/memory.c b/src/memory.c index 59c6d5a..db79e55 100644 --- a/src/memory.c +++ b/src/memory.c @@ -13,7 +13,7 @@ can be used to define other memory allocation routines. */ -#include +#include "GKlib.h" /* This is for the global mcore that tracks all heap allocations */ static __thread gk_mcore_t *gkmcore = NULL; diff --git a/src/pqueue.c b/src/pqueue.c index 2fb8515..5d3bcb1 100644 --- a/src/pqueue.c +++ b/src/pqueue.c @@ -9,7 +9,7 @@ The priority queues are generated using the GK_MKPQUEUE macro. \version\verbatim $Id: pqueue.c 10711 2011-08-31 22:23:04Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ diff --git a/src/random.c b/src/random.c index 3698614..e348f05 100644 --- a/src/random.c +++ b/src/random.c @@ -8,7 +8,7 @@ \version\verbatim $Id: random.c 18796 2015-06-02 11:39:45Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ diff --git a/src/rw.c b/src/rw.c index 7cd4391..ab008e5 100644 --- a/src/rw.c +++ b/src/rw.c @@ -8,7 +8,7 @@ * \version\verbatim $Id: rw.c 11078 2011-11-12 00:20:44Z karypis $ \endverbatim */ -#include +#include "GKlib.h" /*************************************************************************/ diff --git a/src/seq.c b/src/seq.c index f267a3e..97ee2d4 100644 --- a/src/seq.c +++ b/src/seq.c @@ -8,7 +8,7 @@ */ -#include +#include "GKlib.h" diff --git a/src/sort.c b/src/sort.c index f0144ae..cb12ead 100644 --- a/src/sort.c +++ b/src/sort.c @@ -13,7 +13,7 @@ these routines where defined. \version\verbatim $Id: sort.c 21050 2017-05-25 03:53:58Z karypis $ \endverbatim */ -#include +#include "GKlib.h" diff --git a/src/string.c b/src/string.c index 562db22..ad49ed6 100644 --- a/src/string.c +++ b/src/string.c @@ -13,7 +13,7 @@ of standard functions (but with enhanced functionality). */ /************************************************************************/ -#include +#include "GKlib.h" @@ -498,7 +498,7 @@ time_t gk_str2time(char *str) time_t rtime; memset(&time, '\0', sizeof(time)); - + if (strptime(str, "%m/%d/%Y %H:%M:%S", &time) == NULL) return -1; diff --git a/src/timers.c b/src/timers.c index bb8f296..2eccabc 100644 --- a/src/timers.c +++ b/src/timers.c @@ -8,7 +8,7 @@ */ -#include +#include "GKlib.h" @@ -35,7 +35,7 @@ double gk_WClockSeconds(void) **************************************************************************/ double gk_CPUSeconds(void) { -//#ifdef __OPENMP__ +//#ifdef _OPENMP #ifdef __OPENMPXXXX__ return omp_get_wtime(); #else diff --git a/src/tokenizer.c b/src/tokenizer.c index 5efd262..2850378 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -12,7 +12,7 @@ split function. */ -#include +#include "GKlib.h" /************************************************************************