add possibility to pass options to cmake via setup.py

This commit is contained in:
Radovan Bast 2015-07-29 22:33:48 +02:00
parent 8b8e95521f
commit cfe2823c09
5 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,11 @@
[project]
name: example
[cxx]
source: ../../../modules/cxx.cmake
[default_build_paths]
source: ../../../modules/default_build_paths.cmake
[src]
source: ../../../modules/src.cmake

View File

@ -0,0 +1,13 @@
# here we test setting -DENABLE_SOMETHING=OFF -DFOO=ON
# setup.py script
option(ENABLE_SOMETHING "Enable something" ON)
option(ENABLE_FOO "Enable FOO" OFF)
if(ENABLE_SOMETHING)
message(FATAL_ERROR "This test failed")
endif()
if(NOT ENABLE_FOO)
message(FATAL_ERROR "This test failed")
endif()
add_executable(example example.cpp)

View File

@ -0,0 +1,7 @@
#include <iostream>
int main()
{
std::cout << "Hello World!";
return 0;
}

View File

@ -114,6 +114,13 @@ def test_cxx_custom():
# ------------------------------------------------------------------------------
def test_extra_cmake_options():
stdout, stderr = configure_build_and_exe('extra_cmake_options', 'python setup.py --cxx=g++ --cmake-options="-DENABLE_SOMETHING=OFF -DENABLE_FOO=ON"')
assert 'Hello World!' in stdout
# ------------------------------------------------------------------------------
def test_cxx():
stdout, stderr = configure_build_and_exe('cxx', 'python setup.py --cxx=g++')
assert 'Hello World!' in stdout

View File

@ -102,6 +102,8 @@ def gen_cmake_command(config):
s.append(" command.append('-DCMAKE_BUILD_TYPE=%s' % arguments['--type'])")
s.append(" command.append('-G \"%s\"' % arguments['--generator'])")
s.append(" for word in arguments['--cmake-options'].split():")
s.append(" command.append('%s' % word)")
s.append("\n return ' '.join(command)")
@ -151,6 +153,7 @@ def gen_setup(config, relative_path):
options.append(['--type=<TYPE>', 'Set the CMake build type (debug, release, or relwithdeb) [default: release].'])
options.append(['--generator=<STRING>', 'Set the CMake build system generator [default: Unix Makefiles].'])
options.append(['--show', 'Show CMake command and exit.'])
options.append(['--cmake-options=<OPTIONS>', 'Define options to CMake [default: None].'])
options.append(['<builddir>', 'Build directory.'])
options.append(['-h --help', 'Show this screen.'])