-
Notifications
You must be signed in to change notification settings - Fork 330
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
base: master
Are you sure you want to change the base?
Changes from all commits
e655032
cf1f760
a7df780
34c8c7d
b0ce833
891128b
e90581c
facc417
2cb8e87
719d31a
4cb417a
e2d0825
146d7d2
5910ad4
0c717c5
6b273e1
f5b9044
9576be7
ee32afd
9e0e2c4
5ffbbec
025ec52
f788575
271eb5a
aeee7fc
f2c98cc
c24f9de
ad8228b
045f44c
4de20b8
a40926c
d30c92f
ca7c03d
99d52cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
#@formatter:off | ||
set(PACKAGE "${PROJECT_NAME}") | ||
set(PACKAGE "fswatch") | ||
set(PACKAGE_NAME "${PACKAGE}") | ||
set(PACKAGE_VERSION "${PROJECT_VERSION}-develop") | ||
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") | ||
set(PACKAGE_STRING "${PACKAGE} ${PACKAGE_VERSION}") | ||
set(PACKAGE_AUTHOR "[email protected]") | ||
set(PACKAGE_BUGREPORT "${PACKAGE_AUTHOR}") | ||
set(PACKAGE_TARNAME "${PACKAGE}") | ||
|
@@ -29,9 +29,18 @@ set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale" CACHE FILEPATH "loc | |
#@formatter:on | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
if (MSVC) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") | ||
endif (MSVC) | ||
|
||
# control where the static and shared libraries are built so that on windows | ||
# we don't need to tinker with the path to run the executable | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
|
||
# 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
# include modules | ||
include(FindGettext) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain this change with the else block? |
||
else () | ||
set(HAVE_GETOPT_H 1) | ||
set(HAVE_GETOPT_LONG 1) | ||
endif (HAVE_GETOPT_H) | ||
|
||
# If both gettext and libintl are found, define the USE_NLS variable to | ||
|
@@ -60,17 +72,24 @@ if (USE_NLS) | |
set(LINGUAS en en@quot en@boldquot it es) | ||
|
||
foreach (language ${LINGUAS}) | ||
configure_file(${PROJECT_SOURCE_DIR}/po/${language}.po ${PROJECT_BINARY_DIR}/${language}.po COPYONLY) | ||
configure_file("${PROJECT_SOURCE_DIR}/po/${language}.po" "${PROJECT_BINARY_DIR}/${language}.po" COPYONLY) | ||
endforeach () | ||
|
||
gettext_process_pot_file(po/${PACKAGE}.pot ALL INSTALL_DESTINATION share/locale LANGUAGES ${LINGUAS}) | ||
endif () | ||
gettext_process_pot_file("po/${PACKAGE}.pot" ALL INSTALL_DESTINATION "${LOCALEDIR}" LANGUAGES ${LINGUAS}) | ||
endif (USE_NLS) | ||
|
||
# checks | ||
check_cxx_symbol_exists(atexit cstdlib HAVE_ATEXIT) | ||
check_cxx_symbol_exists(setlocale clocale HAVE_SETLOCALE) | ||
check_cxx_symbol_exists(strtod cstdlib HAVE_STRTOD) | ||
|
||
add_subdirectory(libfswatch) | ||
add_subdirectory(fswatch/src) | ||
add_subdirectory(test/src) | ||
option(BUILD_FSWATCH "Build ${PROJECT_NAME}" ON) | ||
option(BUILD_TESTS "Build ${PROJECT_NAME} tests" ON) | ||
|
||
add_subdirectory("libfswatch") | ||
if (BUILD_FSWATCH) | ||
add_subdirectory("fswatch/src") | ||
endif (BUILD_FSWATCH) | ||
if (BUILD_TESTS) | ||
add_subdirectory("test/src") | ||
endif (BUILD_TESTS) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# From: https://github.com/healpy/cfitsio/blob/d02e7ce/FindPthreads.cmake | ||
# - Find the Pthreads library | ||
# This module searches for the Pthreads library (including the | ||
# pthreads-win32 port). | ||
# | ||
# This module defines these variables: | ||
# | ||
# PTHREADS_FOUND | ||
# True if the Pthreads library was found | ||
# PTHREADS_LIBRARY | ||
# The location of the Pthreads library | ||
# PTHREADS_INCLUDE_DIR | ||
# The include path of the Pthreads library | ||
# PTHREADS_DEFINITIONS | ||
# Preprocessor definitions to define | ||
# | ||
# This module responds to the PTHREADS_EXCEPTION_SCHEME | ||
# variable on Win32 to allow the user to control the | ||
# library linked against. The Pthreads-win32 port | ||
# provides the ability to link against a version of the | ||
# library with exception handling. IT IS NOT RECOMMENDED | ||
# THAT YOU USE THIS because most POSIX thread implementations | ||
# do not support stack unwinding. | ||
# | ||
# PTHREADS_EXCEPTION_SCHEME | ||
# C = no exceptions (default) | ||
# (NOTE: This is the default scheme on most POSIX thread | ||
# implementations and what you should probably be using) | ||
# CE = C++ Exception Handling | ||
# SE = Structure Exception Handling (MSVC only) | ||
# | ||
|
||
# | ||
# Define a default exception scheme to link against | ||
# and validate user choice. | ||
# | ||
IF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME) | ||
# Assign default if needed | ||
SET(PTHREADS_EXCEPTION_SCHEME "C") | ||
ELSE(NOT DEFINED PTHREADS_EXCEPTION_SCHEME) | ||
# Validate | ||
IF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND | ||
NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND | ||
NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE") | ||
|
||
MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed") | ||
|
||
ENDIF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND | ||
NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND | ||
NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE") | ||
|
||
IF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE") | ||
MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC") | ||
ENDIF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE") | ||
|
||
ENDIF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME) | ||
|
||
# | ||
# Find the header file | ||
# | ||
FIND_PATH(PTHREADS_INCLUDE_DIR pthread.h) | ||
|
||
# | ||
# Find the library | ||
# | ||
SET(names) | ||
IF(MSVC) | ||
SET(names | ||
pthreadV${PTHREADS_EXCEPTION_SCHEME}2 | ||
pthread | ||
) | ||
ELSEIF(MINGW) | ||
SET(names | ||
pthreadG${PTHREADS_EXCEPTION_SCHEME}2 | ||
pthread | ||
) | ||
ELSE(MSVC) # Unix / Cygwin / Apple | ||
SET(names pthread) | ||
ENDIF(MSVC) | ||
|
||
FIND_LIBRARY(PTHREADS_LIBRARY ${names} | ||
DOC "The Portable Threads Library") | ||
|
||
IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY) | ||
SET(PTHREADS_FOUND true) | ||
SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H) | ||
SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR}) | ||
SET(PTHREADS_LIBRARIES ${PTHREADS_LIBRARY}) | ||
ENDIF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY) | ||
|
||
IF(PTHREADS_FOUND) | ||
IF(NOT PTHREADS_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found Pthreads: ${PTHREADS_LIBRARY}") | ||
ENDIF(NOT PTHREADS_FIND_QUIETLY) | ||
ELSE(PTHREADS_FOUND) | ||
IF(PTHREADS_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find the Pthreads Library") | ||
ENDIF(PTHREADS_FIND_REQUIRED) | ||
ENDIF(PTHREADS_FOUND) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
fswatch.hpp | ||
gettext.h) | ||
set(EXEC_NAME "fswatch_bin") | ||
set(Header_Files "${PACKAGE}.hpp" "gettext.h") | ||
source_group("${PACKAGE} Header Files" FILES "${Header_Files}") | ||
|
||
add_executable(fswatch ${FSWATCH_SRC_FILES}) | ||
set(Source_Files "${PACKAGE}.cpp") | ||
source_group("${PACKAGE} Source Files" FILES "${Source_Files}") | ||
|
||
# check for gettext and libintl | ||
if (USE_NLS) | ||
if (Intl_LIBRARIES) | ||
target_link_libraries(fswatch PRIVATE ${Intl_LIBRARIES}) | ||
endif () | ||
endif () | ||
add_executable("${EXEC_NAME}" "${Header_Files}" "${Source_Files}") | ||
|
||
set_target_properties( | ||
"${EXEC_NAME}" | ||
PROPERTIES | ||
LINKER_LANGUAGE | ||
CXX | ||
) | ||
|
||
if (MSVC) | ||
add_subdirectory("./windows") | ||
target_link_libraries("${EXEC_NAME}" PRIVATE "getopt") | ||
endif (MSVC) | ||
|
||
target_include_directories(fswatch PUBLIC ../.. .) | ||
target_include_directories(fswatch PRIVATE ${PROJECT_BINARY_DIR}) | ||
target_link_libraries(fswatch PUBLIC libfswatch) | ||
target_link_libraries("${EXEC_NAME}" PUBLIC "libfswatch") | ||
|
||
install(TARGETS fswatch DESTINATION bin) | ||
if (DEFINED VCPKG_LIBRARY_LINKAGE) | ||
if (VCPKG_LIBRARY_LINKAGE STREQUAL "static") | ||
set(BUILD_IS_STATIC "ON") | ||
endif (VCPKG_LIBRARY_LINKAGE STREQUAL "static") | ||
elseif (BUILD_SHARED_LIBS) | ||
set(BUILD_IS_STATIC "OFF") | ||
endif () | ||
|
||
if (BUILD_IS_STATIC STREQUAL "ON") | ||
set(bin_install_dir "${CURRENT_PACKAGES_DIR}") | ||
else () | ||
install(FILES ${Header_Files} DESTINATION "include") | ||
set(bin_install_dir "bin") | ||
endif () | ||
install(TARGETS "${EXEC_NAME}" DESTINATION "${bin_install_dir}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?