Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC support; [.github/workflows/cmake.yml] Add macOS and Windows building + testing #282

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

SamuelMarks
Copy link

@SamuelMarks SamuelMarks commented Nov 25, 2021

Added MSVC support, cross-platform testing in CI, and switched to more secure variants of C stdlib function (whence enabled or MSVC).

This closes #176, next is to close #251 (vcpkg is what I use for the rest of my deps).

…s; add vcpkg dependency; cache vcpkg; install pthreads with vcpkg; use vcpkg in cmake configuration
…every step; [libfswatch/CMakeLists.txt] Use `PThreads4W::PThreads4W` and `find_package` on MSVC variant
…c++/windows/cygwin_paths.cpp] Rename original for cygwin only; [src/libfswatch/c++/windows/win_paths.cpp] Use std functions to switch between std::wstring and std::string; [src/libfswatch/c++/windows/win_directory_change_event.hpp] Rename macro close comment
…++/windows/win_paths.cpp] Use different implementation
…cmake.yml] Invert slash ; [src/libfswatch/c++/windows/win_paths.cpp] Use different implementation; [src/libfswatch/c++/windows/win_paths.hpp] Use const ref; [src/libfswatch/c++/windows/cygwin_paths.cpp] Switch to const ref
@SamuelMarks SamuelMarks changed the title [.github/workflows/cmake.yml] Add macOS and Windows building + testing MSVC support; [.github/workflows/cmake.yml] Add macOS and Windows building + testing Nov 25, 2021
…ll}_monitor.cpp}] Use \ on Windows (MSVC) and / everywhere else
…c\fswatch.cpp] Use windows optarg; use secure variants of `gmtime` & `localtime`; [fswatch\src\CMakeLists.txt] Add getopt dir/lib on MSVC; [fswatch\src\windows] getopt port for MSVC; [libfswatch] MSVC variants
…MSVC; [CMakeLists.txt] Enable getopt on msvc; [test/src/CMakeLists.txt] Add `source_group`s; [fswatch/CMakeLists.txt] Add `source_group`s; install headers to include; `add_subdirectory` for `PUBLIC` getopt; [fswatch/windows/CMakeLists.txt] Install properly
… MSVC; [fswatch\src\fswatch.cpp] Print error; [fswatch\src\libfswatch\c\cevent.h] Use `size_t` instead of `unsigned int` to match expected type; [fswatch\src\libfswatch\c++\windows\win_directory_change_event.cpp] Cast types; deduplicate mask; [fswatch\src\libfswatch\filter.cpp] Use `size_t` for index and length; [fswatch\src\libfswatch\monitor.cpp] print error; [fswatch\test\src\fswatch.c] Use `size_t` for `event_num`
@SamuelMarks SamuelMarks mentioned this pull request Dec 23, 2021
…stall`; use `list(APPEND` rather than `set(<var> <var>`; [libfswatch/CMakeLists.txt] use explicit var over pattern matching for install
…present. These files can prevent the core C++ runtime and other packages from compiling correctly"; [fswatch/src/CMakeLists.txt] Only install headers to `include` and to `bin` when `BUILD_SHARED_LIBS` (as per vcpkg policy)
… to install headers to `include` and to `bin` (as per vcpkg policy)
…cies and include directories transitive, removing relative directories and non-install compatible paths in the process (via build expressions)
…res; [fswatch\src\windows] Use CMake approach to symbol exporting; [fswatch\CMakeLists.txt] `PTHREADS4W_FOUND` is the correct condition
…|.hpp file, turning them into libraries, and ensuring that all the libraries have the right dependencies added; use new namespace-free header `#include`s; [src\libfswatch\c\windows\realpath.c] Use CMake export macro; remove `__restrict__` (didn't seem to be supported in MSVC)
…KE_CURRENT_BINARY_DIR}; add ${CMAKE_CURRENT_BINARY_DIR} to `target_include_directories`; [libfswatch\src\libfswatch\c\windows\realpath.c] Use `_access` over `access` to quell POSIX compliancy warning from MSVC
…windows\win_directory_change_event.cpp] Do not include intrinsics (for x86 support)
…ly what is needed (gaining x86 Windows support in the process)
…VC` condition; [libfswatch/src/libfswatch/c++/*_monitor.cpp] Flatten `#include` namespace to match new one from multi-CMakeLists.txt refactor
…C_COMPILER_ARCHITECTURE_ID`; [src\libfswatch\c++\{path_utils,poll_monitor,windows/win_strings}.cpp] Guard intrinsics to only be included `#if defined(_X86_) || defined(_AMD64_)`
…TURE_ID` || `CMAKE_CXX_COMPILER_ARCHITECTURE_ID` || `CMAKE_SYSTEM_PROCESSOR`; [src\libfswatch\c++\windows\{win_directory_change_Event,win_error_message,win_handle}.cpp,win_handle.hpp,src\libfswatch\c++\windows_monitor.cpp] Guard intrinsics to only be included `#if defined(_X86_) || defined(_AMD64_)`
…ching what windows headers expect (tested on x86 and x64 so far)
…for; [*.cpp,win_handle.hpp] Use negative ARM check for including intrinsics
Copy link
Owner

@emcrisostomo emcrisostomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I think this is great work, and puts us very close to having both Autotools and CMake builds available.

But we're still not there: now, the Autotools build is broken (I've added some comments to the PR). Would you be willing to review this, so that we end up with a fully functioning and tested PR that still builds with the same behaviour in all the supported operating systems?

As is, I'm not able to pull it, and I'm not able to test your work on Windows.

Thanks!

@@ -0,0 +1,42 @@
set(LIBRARY_NAME "getopt")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you're creating multiple libraries etc., but it's odd, if not wrong, that the GNU gettext files are inside a directory called windows.

@@ -13,22 +13,41 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
set(FSWATCH_SRC_FILES
fswatch.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to many other places: why are we quoting strings when not required?

#include "event.hpp"
#include "monitor.hpp"
#include "monitor_factory.hpp"
#include "fsw_error.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we rename files and change the include paths, we should keep the build system working, and autotools are now broken

@@ -21,9 +21,9 @@
#include <io.h>
#include <stdlib.h>
#include <errno.h>
#include "cfswatch_export.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not generated by the build system, so the build breaks when using the Autotools

#include "libfswatch/c/libfswatch.h"
#include "libfswatch/c/libfswatch_log.h"
#include "libfswatch/c++/libfswatch_exception.hpp"
#include "path_utils.hpp"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the library prefix was a conscious choice. Why would this refactor be required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can change to using hte full paths

@@ -31,6 +31,7 @@
# include <vector>
# include <iostream>
# include "../c/cevent.h"
# include "cxxfswatch_export.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the C case, this file is not generated by the Autotools thus breaking the build

# this program. If not, see <http://www.gnu.org/licenses/>.
#

set(LIBRARY_NAME "gettext")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this does not belong to Gettext at all

@@ -14,13 +14,13 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.8)
project(fswatch VERSION 1.16.0 LANGUAGES C CXX)
project(fs_watch VERSION 1.17.0 LANGUAGES C CXX)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?


# Add option to choose between shared and static libraries
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not change defaults people is relying on: the point of this setting is for anybody to override

@@ -44,7 +53,10 @@ include(CheckCXXSymbolExists)
check_include_file_cxx(getopt.h HAVE_GETOPT_H)

if (HAVE_GETOPT_H)
check_cxx_symbol_exists(getopt_long getopt.h HAVE_GETOPT_LONG)
check_cxx_symbol_exists(getopt_long "getopt.h" HAVE_GETOPT_LONG)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this change with the else block?

@SamuelMarks
Copy link
Author

@emcrisostomo I'll review your requested changes when I get the chance—my last commit was in February, first PR sent in November—and amend accordingly.

I can maintain compatibility with autotools (I suppose), for the symbol exporters I can create a pure C header file with the necessary ifdefs for each of gcc, clang, and msvc. If you want more than those compilers then I guess expand the list yourself. Alternatively; and preferably; Makefiles can be generated from CMake.

@emcrisostomo emcrisostomo force-pushed the master branch 2 times, most recently from a994138 to 70fe7a5 Compare June 17, 2022 07:40
@emmenlau
Copy link

I'm actually very much interested in native MSVC support (without the need for Cygwin, dirent.h and other compatibility layers). Does this PR provide native MSVC support? @SamuelMarks , is it still actively pursued?

@SamuelMarks
Copy link
Author

@emmenlau There were a lot of changes requested and compatibility with existing autotools toolchain required.

If I get the chance will make the edits and update to latest master in the process. But really would like a more complete test suite to confirm this all works (not to mention the delayed responses in feedback on the PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vcpkg support (Windows package manager) cmake build issue
3 participants