From ea017429abf7fde567df9d046516114a179a8285 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sun, 6 Jul 2025 14:19:09 +0200 Subject: [PATCH 1/3] CI: Add build-tests for various compilers on Windows and Ubuntu The build setup for this repository is incredibly simple, but unfortunately even recent changes to the CMake have made various platforms and compiler combinations unbuildable. Add a basic CI that at the very least _builds_ the project to demonstrate all these problems, which should all go away when other PRs are merged. --- .github/workflows/ci.yaml | 47 ++++++++++++++++++++++++++++++++++++ Makefile | 5 ++-- cmake/GKlibSystem.cmake | 51 --------------------------------------- 3 files changed, 49 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 cmake/GKlibSystem.cmake diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..610ab56 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,47 @@ +on: + - push + +jobs: + build-linux: + name: Use clang and gcc via "Unix Makefiles" + runs-on: ubuntu-latest + strategy: + matrix: + compiler: [clang, gcc] + steps: + - uses: actions/checkout@v4 + - run: | + cmake -Bbuild -DCMAKE_C_COMPILER=${{ matrix.compiler }} + cmake --build build + + build-windows-ninja: + name: Use clang and clang-cl via Ninja + runs-on: windows-latest + strategy: + matrix: + # On Windows, clang only enables the WIN32 flag in CMake whereas + # clang-cl also enables MSVC, because it has a cl.exe-like interface. + compiler: [clang, clang-cl] + steps: + - uses: actions/checkout@v4 + - run: | + # Use Ninja because the MSBuild toolchain can only configure + # alternative compilers via "toolsets", where only ClangCL is + # supported. + cmake -Bbuild -GNinja -DCMAKE_C_COMPILER=${{ matrix.compiler }} + cmake --build build + + build-windows-msbuild: + name: Use MSVC and clang-cl via MSBuild + runs-on: windows-latest + strategy: + matrix: + toolset: + # The default toolset should be the latest 'v143' when nothing is specified + - + - -TClangCL + steps: + - uses: actions/checkout@v4 + - run: | + cmake -Bbuild ${{ matrix.toolset }} + cmake --build build diff --git a/Makefile b/Makefile index c43a479..e14b66a 100644 --- a/Makefile +++ b/Makefile @@ -72,12 +72,11 @@ ifneq ($(shared), not-set) endif define run-config -mkdir -p $(BUILDDIR) -cd $(BUILDDIR) && cmake $(CURDIR) $(CONFIG_FLAGS) +cmake $(CURDIR) -B"$(BUILDDIR)" $(CONFIG_FLAGS) endef all clean install: $(BUILDDIR) - make -C $(BUILDDIR) $@ + cmake --build $(BUILDDIR) $@ uninstall: xargs rm < $(BUILDDIR)/install_manifest.txt diff --git a/cmake/GKlibSystem.cmake b/cmake/GKlibSystem.cmake deleted file mode 100644 index 249d424..0000000 --- a/cmake/GKlibSystem.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# 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(MSVC) - -if(CYGWIN) - set(GKlib_COPTIONS "${GKlib_COPTIONS} -DCYGWIN") -endif(CYGWIN) - -if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") -# 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() - set(GKlib_COPTIONS "${GKlib_COPTIONS} -march=native") - 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") -endif() - -if(${CMAKE_C_COMPILER_ID} MATCHES "Sun") - set(GKlib_COPTIONS "${GKlib_COPTIONS} -xc99") -endif() - -# Intel compiler -if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") - set(GKlib_COPTIONS "${GKlib_COPTIONS} -xHost -std=c99") -endif() - -# Set the CPU type -if(NO_X86) - set(GKlib_COPTIONS "${GKlib_COPTIONS} -DNO_X86=${NO_X86}") -endif(NO_X86) - - -# Finally set the official C flags. -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GKlib_COPTIONS} ${GKlib_COPTS}") From 22ab84c115f5b494f902ce9547e0771888b60c07 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sun, 6 Jul 2025 14:51:12 +0200 Subject: [PATCH 2/3] Rely on `_WIN32` defined by the compiler not on `WIN32` (no longer defined through CMake) Recent changes no longer include a CMake file that set `-DWIN32` (which was only set for `MSVC` anyway, meaning Windows + `clang` would miss out) resulting in lots of errors when compiling on/for Windows because compatibility code is no longer enabled. Switch all those `#ifdef`s to `_WIN32` which will be compiled by both MSVC and `clang` when compiling for Windows. --- include/gk_arch.h | 2 +- src/error.c | 2 +- src/string.c | 2 +- src/timers.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/gk_arch.h b/include/gk_arch.h index b82fb6a..b05192a 100644 --- a/include/gk_arch.h +++ b/include/gk_arch.h @@ -53,7 +53,7 @@ /************************************************************************* * Architecture-specific modifications **************************************************************************/ -#ifdef WIN32 +#ifdef _WIN32 typedef ptrdiff_t ssize_t; #endif diff --git a/src/error.c b/src/error.c index e2a18cf..bf7ac72 100644 --- a/src/error.c +++ b/src/error.c @@ -174,7 +174,7 @@ void gk_NonLocalExit_Handler(int signum) /**************************************************************************/ char *gk_strerror(int errnum) { -#if defined(WIN32) || defined(__MINGW32__) +#if defined(_WIN32) || defined(__MINGW32__) return strerror(errnum); #else #ifndef SUNOS diff --git a/src/string.c b/src/string.c index 4a3fb14..a7fb551 100644 --- a/src/string.c +++ b/src/string.c @@ -483,7 +483,7 @@ char *gk_time2str(time_t time) -#if !defined(WIN32) && !defined(__MINGW32__) +#if !defined(_WIN32) && !defined(__MINGW32__) /************************************************************************/ /*! \brief Converts a date/time string into its equivalent time_t value diff --git a/src/timers.c b/src/timers.c index bb8f296..3c4030b 100644 --- a/src/timers.c +++ b/src/timers.c @@ -39,7 +39,7 @@ double gk_CPUSeconds(void) #ifdef __OPENMPXXXX__ return omp_get_wtime(); #else - #if defined(WIN32) || defined(__MINGW32__) + #if defined(_WIN32) || defined(__MINGW32__) return((double) clock()/CLOCKS_PER_SEC); #else struct rusage r; From 4a4e0c9777de9673ba667fd4ebfeb238aa9fa2aa Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sun, 6 Jul 2025 15:13:26 +0200 Subject: [PATCH 3/3] Don't link against `m.lib` on all of Windows (not just when not using MSVC) When compiling on/to Windows via LLVM/clang(-cl), the compiler ID is no longer `MSVC` even though `m.lib` should still not be used. Read `WIN32` instead which will always be set when targeting Windows regardless of the compiler being used. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a9a694..b2ae9e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ target_include_directories(${PROJECT_NAME} $) target_link_libraries(${PROJECT_NAME} - PUBLIC $<$>:m>) + PUBLIC $<$>:m>) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}