Windows: Use static pthreads library.
[blender.git] / build_files / build_environment / cmake / pthreads.cmake
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ***** END GPL LICENSE BLOCK *****
18
19 if(WIN32)
20
21                 if(MSVC14) # vs2015 has timespec
22                         set(PTHREAD_CPPFLAGS "/I. /DHAVE_CONFIG_H /D_TIMESPEC_DEFINED ")
23                 else() # everything before doesn't
24                         set(PTHREAD_CPPFLAGS "/I. /DHAVE_CONFIG_H ")
25                 endif()
26
27                 set(PTHREADS_BUILD cd ${BUILD_DIR}/pthreads/src/external_pthreads/ && cd && nmake VC-static /e CPPFLAGS=${PTHREAD_CPPFLAGS} /e XLIBS=/NODEFAULTLIB:msvcr)
28
29                 ExternalProject_Add(external_pthreads
30                         URL ${PTHREADS_URI}
31                         DOWNLOAD_DIR ${DOWNLOAD_DIR}
32                         URL_HASH MD5=${PTHREADS_HASH}
33                         PREFIX ${BUILD_DIR}/pthreads
34                         CONFIGURE_COMMAND echo .
35                         BUILD_COMMAND ${PTHREADS_BUILD}
36                         INSTALL_COMMAND COMMAND
37                                 ${CMAKE_COMMAND} -E copy ${BUILD_DIR}/pthreads/src/external_pthreads/libpthreadVC3${LIBEXT} ${LIBDIR}/pthreads/lib/pthreadVC3${LIBEXT} &&
38                                 ${CMAKE_COMMAND} -E copy ${BUILD_DIR}/pthreads/src/external_pthreads/pthread.h ${LIBDIR}/pthreads/inc/pthread.h &&
39                                 ${CMAKE_COMMAND} -E copy ${BUILD_DIR}/pthreads/src/external_pthreads/sched.h ${LIBDIR}/pthreads/inc/sched.h &&
40                                 ${CMAKE_COMMAND} -E copy ${BUILD_DIR}/pthreads/src/external_pthreads/semaphore.h ${LIBDIR}/pthreads/inc/semaphore.h &&
41                                 ${CMAKE_COMMAND} -E copy ${BUILD_DIR}/pthreads/src/external_pthreads/_ptw32.h ${LIBDIR}/pthreads/inc/_ptw32.h
42                         INSTALL_DIR ${LIBDIR}/pthreads
43                 )
44
45                 if(BUILD_MODE STREQUAL Release)
46                         ExternalProject_Add_Step(external_pthreads after_install
47                                 COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/pthreads/inc/ ${HARVEST_TARGET}/pthreads/include/
48                                 COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/pthreads/lib/ ${HARVEST_TARGET}/pthreads/lib
49                                 DEPENDEES install
50                         )
51                 endif()
52
53 endif()