adapt cmake command to platform

(code contributed by Miro Ilias)
This commit is contained in:
Radovan Bast 2015-06-29 22:24:57 +02:00
parent 6f592ba2f0
commit 13c7398979
2 changed files with 31 additions and 0 deletions

View File

@ -7,3 +7,4 @@ script:
- pep8 --ignore=E501 test/test.py
- pep8 --ignore=E501 lib/config.py
- py.test -vv test/test.py
- py.test -vv lib/config.py

View File

@ -44,6 +44,34 @@ def setup_build_path(build_path):
os.makedirs(build_path, 0o755)
def test_adapt_cmake_command_to_platform():
cmake_command = "FC=foo CC=bar CXX=RABOOF cmake -DTHIS -DTHAT='this and that cmake' .."
res = adapt_cmake_command_to_platform(cmake_command, 'linux')
assert res == cmake_command
res = adapt_cmake_command_to_platform(cmake_command, 'win32')
assert res == "set FC=foo && set CC=bar && set CXX=RABOOF && cmake -DTHIS -DTHAT='this and that cmake' .."
cmake_command = "cmake -DTHIS -DTHAT='this and that cmake' .."
res = adapt_cmake_command_to_platform(cmake_command, 'linux')
assert res == cmake_command
res = adapt_cmake_command_to_platform(cmake_command, 'win32')
assert res == cmake_command
def adapt_cmake_command_to_platform(cmake_command, platform):
"""
Adapt CMake command to MS Windows platform.
"""
if platform == 'win32':
pos = cmake_command.find('cmake')
s = ['set %s &&' % e for e in cmake_command[:pos].split()]
s.append(cmake_command[pos:])
return ' '.join(s)
else:
return cmake_command
def run_cmake(command, build_path, default_build_path):
"""
Execute CMake command.
@ -113,6 +141,8 @@ def configure(root_directory, build_path, cmake_command, only_show):
if not only_show:
setup_build_path(build_path)
cmake_command = adapt_cmake_command_to_platform(cmake_command, sys.platform)
print('%s\n' % cmake_command)
if only_show:
sys.exit(0)