From 22298866fbc07572e4128f5973dc8c7a8d256f14 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Thu, 28 May 2020 23:56:10 +0200 Subject: [PATCH] Make Cygwin build work Originally CMake didn't provide C++ language version flags, so GROMACS managed that itself. Now that GROMACS lets CMake manage it, we always get the -std=c++17 flag, rather than (say) -std=gnu++17 to allow extensions to the std headers. In various places, GROMACS relied on POSIX functionality that is available by default on Linux, but on Cygwin required the GNU extensions to the C++ language dialect. This change fixes several such places, mostly by requiring the POSIX extensions needed. Removed an include of sys/syscall.h that was unused, unnecessary, and only present on Linux. Moved an inclusion of gtest.h from a header into a source file because it was only needed there. Fixed some warnings about unused things. --- cmake/TestPipes.cpp | 4 ++++ docs/release-notes/2021/major/portability.rst | 7 ++++++- src/api/cpp/tests/testingconfiguration.h | 2 -- src/api/cpp/tests/version.cpp | 4 +++- src/external/CMakeLists.txt | 6 +++++- src/gromacs/CMakeLists.txt | 4 ++++ src/gromacs/mdrunutility/threadaffinity.cpp | 1 - src/gromacs/utility/futil.cpp | 5 +++-- src/testutils/TestMacros.cmake | 4 ++++ 9 files changed, 29 insertions(+), 8 deletions(-) diff --git a/cmake/TestPipes.cpp b/cmake/TestPipes.cpp index f6f55ab382..b48e6215ca 100644 --- a/cmake/TestPipes.cpp +++ b/cmake/TestPipes.cpp @@ -1,3 +1,7 @@ +#ifdef __CYGWIN__ + /* Pipes need POSIX things, not just std ones */ + #define _POSIX_C_SOURCE 200809L +#endif #include int diff --git a/docs/release-notes/2021/major/portability.rst b/docs/release-notes/2021/major/portability.rst index b2809ecc0a..1fceecd7d7 100644 --- a/docs/release-notes/2021/major/portability.rst +++ b/docs/release-notes/2021/major/portability.rst @@ -29,5 +29,10 @@ Updated required CMake version to 3.13. C++ standard """""""""""" -GROMACS has updated the required C++ standards compliance from C++14 to C++17, +|Gromacs| has updated the required C++ standards compliance from C++14 to C++17, and requires 2017 standard library features. See the install guide for details. + +Cygwin +"""""" + +|Gromacs| now builds on Cygwin with both gcc and clang compilers. diff --git a/src/api/cpp/tests/testingconfiguration.h b/src/api/cpp/tests/testingconfiguration.h index 3d160d7e14..e7180f8984 100644 --- a/src/api/cpp/tests/testingconfiguration.h +++ b/src/api/cpp/tests/testingconfiguration.h @@ -43,8 +43,6 @@ #include "config.h" -#include - #include "gromacs/gmxpreprocess/grompp.h" #include "gromacs/math/vec.h" #include "gromacs/utility/stringutil.h" diff --git a/src/api/cpp/tests/version.cpp b/src/api/cpp/tests/version.cpp index 9ac87cb47d..251a7ab492 100644 --- a/src/api/cpp/tests/version.cpp +++ b/src/api/cpp/tests/version.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018, by the GROMACS development team, led by + * Copyright (c) 2018,2020, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -35,6 +35,8 @@ #include +#include + #include "gmxapi/version.h" #include "testingconfiguration.h" diff --git a/src/external/CMakeLists.txt b/src/external/CMakeLists.txt index 89dff8121b..f2c31adfa5 100644 --- a/src/external/CMakeLists.txt +++ b/src/external/CMakeLists.txt @@ -2,7 +2,7 @@ # This file is part of the GROMACS molecular simulation package. # # Copyright (c) 2011,2012,2013,2014,2015 by the GROMACS development team. -# Copyright (c) 2016,2019, by the GROMACS development team, led by +# Copyright (c) 2016,2019,2020, by the GROMACS development team, led by # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, # and including many others, as listed in the AUTHORS file in the # top-level source directory and at http://www.gromacs.org. @@ -60,6 +60,10 @@ if(BUILD_TESTING AND GMX_BUILD_UNITTESTS) target_compile_definitions(gtest PRIVATE _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) target_compile_definitions(gtest_main PRIVATE _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) endif() + if (CYGWIN) + # Ensure GoogleTest can find POSIX things it needs + target_compile_definitions(gtest PRIVATE _POSIX_C_SOURCE=200809L) + endif() gmx_target_warning_suppression(gmock -Wno-deprecated-copy HAVE_NO_DEPRECATED_COPY) set(GTEST_IS_THREADSAFE "${GTEST_IS_THREADSAFE}" PARENT_SCOPE) diff --git a/src/gromacs/CMakeLists.txt b/src/gromacs/CMakeLists.txt index 0b369bde85..6ea6f87224 100644 --- a/src/gromacs/CMakeLists.txt +++ b/src/gromacs/CMakeLists.txt @@ -139,6 +139,10 @@ list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES} ${PROPERTY_SOU tmpi_get_source_list(THREAD_MPI_SOURCES ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/src) add_library(thread_mpi OBJECT ${THREAD_MPI_SOURCES}) target_compile_definitions(thread_mpi PRIVATE HAVE_CONFIG_H) +if(CYGWIN) + # Needs POSIX-isms for strdup, not just std-isms + target_compile_definitions(thread_mpi PRIVATE _POSIX_C_SOURCE=200809L) +endif() gmx_target_compile_options(thread_mpi) if (WIN32) gmx_target_warning_suppression(thread_mpi /wd4996 HAS_NO_MSVC_UNSAFE_FUNCTION) diff --git a/src/gromacs/mdrunutility/threadaffinity.cpp b/src/gromacs/mdrunutility/threadaffinity.cpp index fd392ded2f..a2d08a0f59 100644 --- a/src/gromacs/mdrunutility/threadaffinity.cpp +++ b/src/gromacs/mdrunutility/threadaffinity.cpp @@ -45,7 +45,6 @@ #if HAVE_SCHED_AFFINITY # include -# include #endif #include "thread_mpi/threads.h" diff --git a/src/gromacs/utility/futil.cpp b/src/gromacs/utility/futil.cpp index 1b55ec266c..15c986a8d8 100644 --- a/src/gromacs/utility/futil.cpp +++ b/src/gromacs/utility/futil.cpp @@ -170,14 +170,14 @@ static void push_ps(FILE* fp) # undef gmx_ffclose # endif # if (!HAVE_PIPES && !defined(__native_client__)) -static FILE* popen(const char* nm, const char* mode) +static FILE* popen(const char* /* nm */, const char* /* mode */) { gmx_impl("Sorry no pipes..."); return NULL; } -static int pclose(FILE* fp) +static int pclose(FILE* /* fp */) { gmx_impl("Sorry no pipes..."); @@ -697,6 +697,7 @@ int gmx_fsync(FILE* fp) # elif HAVE__FILENO fn = _fileno(fp); # else + GMX_UNUSED_VALUE(fp); fn = -1; # endif diff --git a/src/testutils/TestMacros.cmake b/src/testutils/TestMacros.cmake index d668cb5d9c..36c9631a68 100644 --- a/src/testutils/TestMacros.cmake +++ b/src/testutils/TestMacros.cmake @@ -157,6 +157,10 @@ function (gmx_add_gtest_executable EXENAME) # use for gmx::compat::optional. These are included as system # headers so that no warnings are issued from them. target_include_directories(${EXENAME} SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external) + if(CYGWIN) + # Ensure GoogleTest headers can find POSIX things needed + target_compile_definitions(${EXENAME} PRIVATE _POSIX_C_SOURCE=200809L) + endif() target_link_libraries(${EXENAME} PRIVATE testutils libgromacs gmock -- 2.11.4.GIT