Add blender launcher application when building with MSVC

Main idea of this change is to make a small executable which
will set OMP_WAIT_POLICY environment variable and then will
launch blender itself.

This is a teporary solution for the time being we'll have a
more clear solution to high CPU usage with OpenMP when building
with MSVC.

Reviewers: campbellbarton, juicyfruit

Reviewed By: juicyfruit

Differential Revision: https://developer.blender.org/D717
This commit is contained in:
Sergey Sharybin 2014-08-07 20:01:20 +06:00
parent 26dc8b7c18
commit 0e9c677343
3 changed files with 92 additions and 1 deletions

@ -832,7 +832,17 @@ for x in B.create_blender_liblist(env, 'system'):
thelibincs.append(os.path.dirname(x))
if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
env.BlenderProg(B.root_build_dir, "blender", creob + mainlist + thestatlibs + dobj, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
blender_progname = "blender"
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'):
blender_progname = "blender-app"
lenv = env.Clone()
lenv.Append(LINKFLAGS = env['PLATFORM_LINKFLAGS'])
targetpath = B.root_build_dir + '/blender'
launcher_obj = [env.Object(B.root_build_dir + 'source/creator/creator/creator_launch_win', ['#source/creator/creator_launch_win.c'])]
env.BlenderProg(B.root_build_dir, 'blender', [launcher_obj] + B.resources, [], [], 'blender')
env.BlenderProg(B.root_build_dir, blender_progname, creob + mainlist + thestatlibs + dobj, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
if env['WITH_BF_PLAYER']:
playerlist = B.create_blender_liblist(env, 'player')
playerlist += B.create_blender_liblist(env, 'player2')
@ -882,6 +892,9 @@ if env['OURPLATFORM']!='darwin':
td, tf = os.path.split(targetdir)
dotblenderinstall.append(env.Install(dir=td, source=srcfile))
scriptinstall.append(env.InstallAs(env['BF_INSTALLDIR'] + '/blender-app.exe.manifest',
'source/icons/blender.exe.manifest'))
if env['WITH_BF_PYTHON']:
#-- local/VERSION/scripts
scriptpaths=['release/scripts']

@ -932,3 +932,18 @@ setup_blender_sorted_libs()
target_link_libraries(blender ${BLENDER_SORTED_LIBS})
setup_liblinks(blender)
# -----------------------------------------------------------------------------
# Setup launcher
if(WIN32 AND NOT WITH_PYTHON_MODULE)
set(LAUNCHER_SRC
creator_launch_win.c
../icons/winblender.rc
)
add_executable(blender-launcher ${LAUNCHER_SRC})
target_link_libraries(blender-launcher ${PLATFORM_LINKLIBS})
set_target_properties(blender PROPERTIES OUTPUT_NAME blender-app)
set_target_properties(blender-launcher PROPERTIES OUTPUT_NAME blender)
endif()

@ -0,0 +1,63 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2014 by Blender Foundation.
* All rights reserved.
*
* Contributor(s): Sergey Sharybin.
*
* ***** END GPL LICENSE BLOCK *****
*/
#pragma comment(linker, "/subsystem:windows")
/* Binary name to launch. */
#define BLENDER_BINARY "blender-app.exe"
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
PROCESS_INFORMATION processInformation = {0};
STARTUPINFOA startupInfo = {0};
BOOL result;
_putenv_s("OMP_WAIT_POLICY", "PASSIVE");
startupInfo.cb = sizeof(startupInfo);
result = CreateProcessA(NULL, BLENDER_BINARY, NULL, NULL, FALSE,
0, NULL, NULL,
&startupInfo, &processInformation);
if (!result) {
fprintf(stderr, "Error launching " BLENDER_BINARY "\n");
return EXIT_FAILURE;
}
WaitForSingleObject(processInformation.hProcess, INFINITE);
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
return EXIT_SUCCESS;
}