Fix Windows builds with ccache.
[openjpeg.git] / cscript
1 import os
2
3 def build(target, options):
4     cmd = 'cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%s -DBUILD_PKGCONFIG_FILES=ON' % target.directory
5     if target.platform == 'windows':
6         # Hack: the build fails if PATH includes /opt/windows/64/bin; I don't know why:
7         # remove it
8         target.set('PATH', '%s:%s' % (target.tool_path, os.environ['PATH']))
9         f = open('mingw.cmake', 'w')
10         print("SET(CMAKE_SYSTEM_NAME Windows)", file=f)
11         cc = target.get('CC')
12         cc = cc.replace("ccache ", "")
13         cc = cc.replace("\"", "")
14         if target.ccache:
15             print("set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)", file=f)
16         print("SET(CMAKE_C_COMPILER %s/%s)" % (target.tool_path, cc), file=f)
17         print("SET(CMAKE_RC_COMPILER %s/%s)" % (target.tool_path, target.get('WINRC')), file=f)
18         all = "%s " % target.library_prefix
19         print("SET(CMAKE_ROOT_FIND_PATH %s %s)" % (all, target.tool_path), file=f)
20         print("SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)", file=f)
21         print("SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)", file=f)
22         print("SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)", file=f)
23         cmd += ' -DCMAKE_TOOLCHAIN_FILE=mingw.cmake'
24         f.close()
25     if target.platform == 'linux':
26         cmd += ' -DBUILD_SHARED_LIBS=OFF'
27     if target.platform == 'osx':
28         cmd += ' -DCMAKE_OSX_SYSROOT=%s/MacOSX%s.sdk' % (target.sdk_prefix, target.sdk)
29
30     target.command(cmd)
31     target.command('make -j%d VERBOSE=1' % target.parallel)
32     target.command('make install')