Skip to content

Commit

Permalink
CMake support and Travis CI job
Browse files Browse the repository at this point in the history
  • Loading branch information
jwinarske committed Nov 26, 2019
1 parent 44daa24 commit ded980f
Show file tree
Hide file tree
Showing 22 changed files with 970 additions and 1,476 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ tests/benchlib.o
tests/SIZES.*
tests/*.log
/.project
build
PTHREADS-BUILT
.vscode
108 changes: 108 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
language: shell

os: windows

env:
- BUILD_TYPE=Debug VS2017=amd64 TESTING=OFF
- BUILD_TYPE=Release VS2017=amd64 TESTING=OFF
- BUILD_TYPE=MinSizeRel VS2017=amd64 TESTING=OFF
- BUILD_TYPE=MinSizeRel VS2017=amd64 TESTING=OFF

- BUILD_TYPE=Debug VS2017=amd64_x86 TESTING=OFF
- BUILD_TYPE=Release VS2017=amd64_x86 TESTING=OFF
- BUILD_TYPE=MinSizeRel VS2017=amd64_x86 TESTING=OFF
- BUILD_TYPE=MinSizeRel VS2017=amd64_x86 TESTING=OFF

#- BUILD_TYPE=Debug VS2017=amd64_arm TESTING=OFF
#- BUILD_TYPE=Release VS2017=amd64_arm TESTING=OFF
#- BUILD_TYPE=MinSizeRel VS2017=amd64_arm TESTING=OFF
#- BUILD_TYPE=MinSizeRel VS2017=amd64_arm TESTING=OFF

#- BUILD_TYPE=Debug VS2017=amd64_arm64 TESTING=OFF
#- BUILD_TYPE=Release VS2017=amd64_arm64 TESTING=OFF
#- BUILD_TYPE=MinSizeRel VS2017=amd64_arm64 TESTING=OFF
#- BUILD_TYPE=MinSizeRel VS2017=amd64_arm64 TESTING=OFF

#install:
#- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
#- mkdir ${DEPS_DIR} && cd ${DEPS_DIR} && pwd
#- travis_retry wget --no-check-certificate https://cmake.org/files/v3.11/cmake-3.11.0-win64-x64.zip
#- echo "615dfb0813443c1ff56ae0e9d6dbfc61 *cmake-3.11.0-win64-x64.zip" > cmake_md5.txt
#- md5sum -c cmake_md5.txt
#- 7z x -y cmake-3.11.0-win64-x64.zip
#- PATH=${DEPS_DIR}/cmake-3.11.0-win64-x64:${DEPS_DIR}/cmake-3.11.0-win64-x64/bin:$PATH

before_script:

# document the version
#- cmake --version
#- cmake --help

# set enviromental variables
- ls "/c/Progra~2/Microsoft Visual Studio/2017/BuildTools/VC/Auxiliary/Build/"
#vcvars32.bat
#vcvars64.bat
#vcvarsall.bat
#vcvarsamd64_arm.bat
#vcvarsamd64_arm64.bat
#vcvarsamd64_x86.bat
#vcvarsx86_amd64.bat
#vcvarsx86_arm.bat
#vcvarsx86_arm64.bat
#- printenv

#- msvcenv="__msvc.bat"
#- echo "@echo off" > "$msvcenv"
#- echo "call /c/Progra~2/Microsoft\ Visual\ Studio/2017/BuildTools/VC/Auxiliary/Build/vcvarsall.bat ${VS2017}" >> "$msvcenv"
#- echo "set" >> "$msvcenv"
#- cmd "/K $msvcenv"
# > "$msenv.tmp"

#- cat "$msvcenv"
#- rm -f "$msvcenv"

- printenv

#- cat "$msenv.tmp"

#- grep -e '^PATH=' "$msenv.tmp" | \
#sed \
#-e 's/\(.*\)=\(.*\)/export \1="\2:$PATH"/g' \
#-e 's/\([a-zA-Z]\):[\\\/]/\/\1\//g' \
#-e 's/\\/\//g' -e 's/;\//:\//g'
# > "$msenv"
#- grep -e '^(INCLUDE|LIB|LIBPATH)=' "$msenv.tmp" | sed -e 's/\(.*\)=\(.*\)/export \1="\2"/g' >> "$msenv"
#- rm "$msenv.tmp"
#- cat "$msenv"
#- source "$msenv"

#- printenv

- call "c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars32.bat" ${VS2017}
#- cmd "/K C:\\Progra~2\\Microsoft\ Visual\ Studio\\2017\\BuildTools\\VC\\Auxiliary\\Build\\vcvarsall.bat ${VS2017}"
#- /c/Progra~2/Microsoft\ Visual\ Studio/2017/BuildTools/VC/Auxiliary/Build/vcvarsall.bat ${VS2017} > "$msenv.tmp"
#- cat "$msenv.tmp"
#- printenv

# Visual Studio 2015
#- ls "/c/Progra~2/Microsoft Visual Studio 14.0/VC/"
#- /c/Progra~2/Microsoft\ Visual\ Studio\ 14.0/VC/vcvarsall.bat amd64

# generate the build files
- cd ${TRAVIS_BUILD_DIR} && mkdir build && cd build
- cmake -G"NMake Makefiles" -DCMAKE_VERBOSE_MAKEFILE=FALSE -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
#-DBUILD_NUMBER=${TRAVIS_BUILD_NUMBER}
#-DDIST_ROOT="${TRAVIS_BUILD_DIR}/build/dist"
#-DENABLE_TESTS=${TESTING}
#..
script:
- cmake --build . --config ${BUILD_TYPE} --target install

addons:
coverity_scan:
project:
name: “jwinarske/pthreads4w"
notification_email: [email protected]
build_command_prepend: "mkdir build && cd build && cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE -DDCMAKE_INSTALL_PREFIX=`pwd`/dist .."
build_command: "cmake --build . --target install"
branch_pattern: coverity_scan
155 changes: 155 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
cmake_minimum_required(VERSION 3.11)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Choose the type of build, options are: Debug, Release, or MinSizeRel." FORCE)
message(STATUS "No build type specified, defaulting to MinSizeRel.")
endif()

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake")

include (get_version)

message(STATUS "Generator ......... ${CMAKE_GENERATOR}")
message(STATUS "Build Type ........ ${CMAKE_BUILD_TYPE}")
message(STATUS "Version ........... ${PTHREADS4W_VERSION}")

project(pthreads4w VERSION ${PTHREADS4W_VERSION} LANGUAGES C)

set(PTW32_VER ${PROJECT_VERSION_MAJOR}${EXTRAVERSION})
set(CMAKE_DEBUG_POSTFIX d)

# Uncomment this if config.h defines RETAIN_WSALASTERROR
#set(XLIBS wsock32.lib)


include_directories(.)

#################################
# Target Arch #
#################################
include (target_arch)

get_target_arch(TARGET_ARCH)

if(${TARGET_ARCH} STREQUAL "ARM")
add_definitions(-D__PTW32_ARCHARM -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1)
elseif(${TARGET_ARCH} STREQUAL "ARM64")
add_definitions(-D__PTW32_ARCHARM64 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1)
elseif(${TARGET_ARCH} STREQUAL "x86_64")
add_definitions(-D__PTW32_ARCHAMD64)
elseif(${TARGET_ARCH} STREQUAL "x86")
add_definitions(-D__PTW32_ARCHX86)
elseif(${TARGET_ARCH} STREQUAL "x64")
add_definitions(-D__PTW32_ARCHX64)
else()
MESSAGE(ERROR "\"${TARGET_ARCH}\" not supported in version.rc")
endif()
message(STATUS "Target ............ ${TARGET_ARCH}")

if(MSVC)
message(STATUS "MSVC Version ...... ${MSVC_VERSION}")
endif()

#################################
# Install Path #
#################################
if(DIST_ROOT)
set(CMAKE_INSTALL_PREFIX "${DIST_ROOT}")
else()
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/PTHREADS-BUILT")
endif()
message(STATUS "Install Path ${CMAKE_INSTALL_PREFIX}")


set(DLLDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/bin)
set(LIBDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/lib)
set(HDRDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/include)
set(TESTDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/test)

#################################
# Defs #
#################################
add_definitions(-D__PTW32_BUILD_INLINED)

if(MSVC)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /errorReport:none /nologo ")

# C++ Exceptions
# (Note: If you are using Microsoft VC++6.0, the library needs to be built
# with /EHa instead of /EHs or else cancellation won't work properly.)
if(MSVC_VERSION EQUAL 1200)
set(VCEFLAGS "/EHa /TP ")
else()
set(VCEFLAGS "/EHs /TP ")
endif()

add_definitions(-DHAVE_CONFIG_H -D__PTW32_RC_MSC)

endif()

# Update filename with proper version info
configure_file(${CMAKE_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_BINARY_DIR}/version.rc @ONLY)

#################################
# Libraries #
#################################
set(targ_suffix "")
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(targ_suffix ${CMAKE_DEBUG_POSTFIX})
endif()

macro(shared_lib type def)
set(targ pthread${type}${PTW32_VER})
add_library(${targ} SHARED pthread.c ${CMAKE_BINARY_DIR}/version.rc)
message(STATUS ${targ})
target_compile_definitions(${targ} PUBLIC "-D${def}")
if(${type} STREQUAL "VCE")
set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS})
endif()
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.dll DESTINATION ${DLLDEST})
install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST})
else()
install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.dll DESTINATION ${DLLDEST})
install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST})
endif()
endmacro()

macro(static_lib type def)
set(targ libpthread${type}${PTW32_VER})
add_library(${targ} STATIC pthread.c)
message(STATUS ${targ})
target_compile_definitions(${targ} PUBLIC "-D${def}" -D__PTW32_STATIC_LIB)
if(${type} STREQUAL "VCE")
set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS})
endif()
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST})
else()
install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST})
endif()
endmacro()

shared_lib ( VCE __PTW32_CLEANUP_CXX )
shared_lib ( VSE __PTW32_CLEANUP_SEH )
shared_lib ( VC __PTW32_CLEANUP_C )

static_lib ( VCE __PTW32_CLEANUP_CXX )
static_lib ( VSE __PTW32_CLEANUP_SEH )
static_lib ( VC __PTW32_CLEANUP_C )

#################################
# Install #
#################################
install(FILES _ptw32.h pthread.h sched.h semaphore.h DESTINATION ${HDRDEST})

#################################
# Test #
#################################
option(ENABLE_TESTS "Enable Test code build" FALSE)

#TODO determine if cross compile...
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2019-11-03 Ross Johnson <ross dot johnson at homemail dot com dot au>

* NOTICE: Remove third party code acknowledgments because files have been
removed from distro.

2018-08-19 Ross Johnson <ross dot johnson at homemail dot com dot au>

* context.h (__PTW32_PROCPTR): Added missing '__' prefix for v3.
Expand Down
24 changes: 1 addition & 23 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,4 @@ Copyright 1999-2018, Pthreads4w contributors

This product includes software developed through the colaborative
effort of several individuals, each of whom is listed in the file
CONTRIBUTORS included with this software.

The following files are not covered under the Copyrights
listed above:

[1] tests/rwlock7.c
[1] tests/rwlock7_1.c
[1] tests/rwlock8.c
[1] tests/rwlock8_1.c
[2] tests/threestage.c

[1] The file tests/rwlock7.c and those similarly named are derived from
code written by Dave Butenhof for his book 'Programming With POSIX(R)
Threads'. The original code was obtained by free download from his
website http://home.earthlink.net/~anneart/family/Threads/source.html

[2] The file tests/threestage.c is taken directly from examples in the
book "Windows System Programming, Edition 4" by Johnson (John) Hart
Session 6, Chapter 10. ThreeStage.c
Several required additional header and source files from the
book examples have been included inline to simplify compilation.
The only modification to the code has been to provide default
values when run without arguments.
CONTRIBUTORS included with this software.
6 changes: 3 additions & 3 deletions _ptw32.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
*/
#define __PTW32_VERSION_MAJOR 3
#define __PTW32_VERSION_MINOR 0
#define __PTW32_VERSION_MICRO 1
#define __PTW32_VERSION_MICRO 2
#define __PTW32_VERION_BUILD 0
#define __PTW32_VERSION 3,0,0,1
#define __PTW32_VERSION_STRING "3, 0, 1, 0\0"
#define __PTW32_VERSION 3,0,2,0
#define __PTW32_VERSION_STRING "3, 0, 2, 0\0"

#if defined(__GNUC__)
# pragma GCC system_header
Expand Down
Loading

0 comments on commit ded980f

Please sign in to comment.