|
| 1 | +cmake_minimum_required(VERSION 3.11) |
| 2 | + |
| 3 | +if(NOT CMAKE_BUILD_TYPE) |
| 4 | + set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Choose the type of build, options are: Debug, Release, or MinSizeRel." FORCE) |
| 5 | + message(STATUS "No build type specified, defaulting to MinSizeRel.") |
| 6 | +endif() |
| 7 | + |
| 8 | +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") |
| 9 | + |
| 10 | +include (get_version) |
| 11 | + |
| 12 | +message(STATUS "Generator ......... ${CMAKE_GENERATOR}") |
| 13 | +message(STATUS "Build Type ........ ${CMAKE_BUILD_TYPE}") |
| 14 | +message(STATUS "Version ........... ${PTHREADS4W_VERSION}") |
| 15 | + |
| 16 | +project(pthreads4w VERSION ${PTHREADS4W_VERSION} LANGUAGES C) |
| 17 | + |
| 18 | +set(PTW32_VER ${PROJECT_VERSION_MAJOR}${EXTRAVERSION}) |
| 19 | +set(CMAKE_DEBUG_POSTFIX d) |
| 20 | + |
| 21 | +# Uncomment this if config.h defines RETAIN_WSALASTERROR |
| 22 | +#set(XLIBS wsock32.lib) |
| 23 | + |
| 24 | + |
| 25 | +include_directories(.) |
| 26 | + |
| 27 | +################################# |
| 28 | +# Target Arch # |
| 29 | +################################# |
| 30 | +include (target_arch) |
| 31 | + |
| 32 | +get_target_arch(TARGET_ARCH) |
| 33 | + |
| 34 | +if(${TARGET_ARCH} STREQUAL "ARM") |
| 35 | + add_definitions(-D__PTW32_ARCHARM -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1) |
| 36 | +elseif(${TARGET_ARCH} STREQUAL "ARM64") |
| 37 | + add_definitions(-D__PTW32_ARCHARM64 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1) |
| 38 | +elseif(${TARGET_ARCH} STREQUAL "x86_64") |
| 39 | + add_definitions(-D__PTW32_ARCHAMD64) |
| 40 | +elseif(${TARGET_ARCH} STREQUAL "x86") |
| 41 | + add_definitions(-D__PTW32_ARCHX86) |
| 42 | +elseif(${TARGET_ARCH} STREQUAL "x64") |
| 43 | + add_definitions(-D__PTW32_ARCHX64) |
| 44 | +else() |
| 45 | + MESSAGE(ERROR "\"${TARGET_ARCH}\" not supported in version.rc") |
| 46 | +endif() |
| 47 | +message(STATUS "Target ............ ${TARGET_ARCH}") |
| 48 | + |
| 49 | +if(MSVC) |
| 50 | + message(STATUS "MSVC Version ...... ${MSVC_VERSION}") |
| 51 | +endif() |
| 52 | + |
| 53 | +################################# |
| 54 | +# Install Path # |
| 55 | +################################# |
| 56 | +if(DIST_ROOT) |
| 57 | + set(CMAKE_INSTALL_PREFIX "${DIST_ROOT}") |
| 58 | +else() |
| 59 | + set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/PTHREADS-BUILT") |
| 60 | +endif() |
| 61 | +message(STATUS "Install Path ${CMAKE_INSTALL_PREFIX}") |
| 62 | + |
| 63 | + |
| 64 | +set(DLLDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/bin) |
| 65 | +set(LIBDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/lib) |
| 66 | +set(HDRDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/include) |
| 67 | +set(TESTDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/test) |
| 68 | + |
| 69 | +################################# |
| 70 | +# Defs # |
| 71 | +################################# |
| 72 | +add_definitions(-D__PTW32_BUILD_INLINED) |
| 73 | + |
| 74 | +if(MSVC) |
| 75 | + |
| 76 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /errorReport:none /nologo ") |
| 77 | + |
| 78 | + # C++ Exceptions |
| 79 | + # (Note: If you are using Microsoft VC++6.0, the library needs to be built |
| 80 | + # with /EHa instead of /EHs or else cancellation won't work properly.) |
| 81 | + if(MSVC_VERSION EQUAL 1200) |
| 82 | + set(VCEFLAGS "/EHa /TP ") |
| 83 | + else() |
| 84 | + set(VCEFLAGS "/EHs /TP ") |
| 85 | + endif() |
| 86 | + |
| 87 | + add_definitions(-DHAVE_CONFIG_H -D__PTW32_RC_MSC) |
| 88 | + |
| 89 | +endif() |
| 90 | + |
| 91 | +# Update filename with proper version info |
| 92 | +configure_file(${CMAKE_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_BINARY_DIR}/version.rc @ONLY) |
| 93 | + |
| 94 | +################################# |
| 95 | +# Libraries # |
| 96 | +################################# |
| 97 | +set(targ_suffix "") |
| 98 | +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") |
| 99 | + set(targ_suffix ${CMAKE_DEBUG_POSTFIX}) |
| 100 | +endif() |
| 101 | + |
| 102 | +macro(shared_lib type def) |
| 103 | + set(targ pthread${type}${PTW32_VER}) |
| 104 | + add_library(${targ} SHARED pthread.c ${CMAKE_BINARY_DIR}/version.rc) |
| 105 | + message(STATUS ${targ}) |
| 106 | + target_compile_definitions(${targ} PUBLIC "-D${def}") |
| 107 | + if(${type} STREQUAL "VCE") |
| 108 | + set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS}) |
| 109 | + endif() |
| 110 | + if(${CMAKE_GENERATOR} MATCHES "Visual Studio") |
| 111 | + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.dll DESTINATION ${DLLDEST}) |
| 112 | + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST}) |
| 113 | + else() |
| 114 | + install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.dll DESTINATION ${DLLDEST}) |
| 115 | + install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST}) |
| 116 | + endif() |
| 117 | +endmacro() |
| 118 | + |
| 119 | +macro(static_lib type def) |
| 120 | + set(targ libpthread${type}${PTW32_VER}) |
| 121 | + add_library(${targ} STATIC pthread.c) |
| 122 | + message(STATUS ${targ}) |
| 123 | + target_compile_definitions(${targ} PUBLIC "-D${def}" -D__PTW32_STATIC_LIB) |
| 124 | + if(${type} STREQUAL "VCE") |
| 125 | + set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS}) |
| 126 | + endif() |
| 127 | + if(${CMAKE_GENERATOR} MATCHES "Visual Studio") |
| 128 | + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST}) |
| 129 | + else() |
| 130 | + install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST}) |
| 131 | + endif() |
| 132 | +endmacro() |
| 133 | + |
| 134 | +shared_lib ( VCE __PTW32_CLEANUP_CXX ) |
| 135 | +shared_lib ( VSE __PTW32_CLEANUP_SEH ) |
| 136 | +shared_lib ( VC __PTW32_CLEANUP_C ) |
| 137 | + |
| 138 | +static_lib ( VCE __PTW32_CLEANUP_CXX ) |
| 139 | +static_lib ( VSE __PTW32_CLEANUP_SEH ) |
| 140 | +static_lib ( VC __PTW32_CLEANUP_C ) |
| 141 | + |
| 142 | +################################# |
| 143 | +# Install # |
| 144 | +################################# |
| 145 | +install(FILES _ptw32.h pthread.h sched.h semaphore.h DESTINATION ${HDRDEST}) |
| 146 | + |
| 147 | +################################# |
| 148 | +# Test # |
| 149 | +################################# |
| 150 | +option(ENABLE_TESTS "Enable Test code build" FALSE) |
| 151 | + |
| 152 | +#TODO determine if cross compile... |
| 153 | +if(ENABLE_TESTS) |
| 154 | + add_subdirectory(tests) |
| 155 | +endif() |
0 commit comments