From cfe2823c09d987fff1cd540c218c73a53cfddfe0 Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Wed, 29 Jul 2015 22:33:48 +0200 Subject: [PATCH] add possibility to pass options to cmake via setup.py --- test/extra_cmake_options/cmake/autocmake.cfg | 11 +++++++++++ test/extra_cmake_options/src/CMakeLists.txt | 13 +++++++++++++ test/extra_cmake_options/src/example.cpp | 7 +++++++ test/test.py | 7 +++++++ update.py | 3 +++ 5 files changed, 41 insertions(+) create mode 100644 test/extra_cmake_options/cmake/autocmake.cfg create mode 100644 test/extra_cmake_options/src/CMakeLists.txt create mode 100644 test/extra_cmake_options/src/example.cpp diff --git a/test/extra_cmake_options/cmake/autocmake.cfg b/test/extra_cmake_options/cmake/autocmake.cfg new file mode 100644 index 0000000..e35cf0c --- /dev/null +++ b/test/extra_cmake_options/cmake/autocmake.cfg @@ -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 diff --git a/test/extra_cmake_options/src/CMakeLists.txt b/test/extra_cmake_options/src/CMakeLists.txt new file mode 100644 index 0000000..9fc7202 --- /dev/null +++ b/test/extra_cmake_options/src/CMakeLists.txt @@ -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) diff --git a/test/extra_cmake_options/src/example.cpp b/test/extra_cmake_options/src/example.cpp new file mode 100644 index 0000000..4dd9d62 --- /dev/null +++ b/test/extra_cmake_options/src/example.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + std::cout << "Hello World!"; + return 0; +} diff --git a/test/test.py b/test/test.py index 6bd21e3..471d437 100644 --- a/test/test.py +++ b/test/test.py @@ -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 diff --git a/update.py b/update.py index 5e6a71f..44dc9b0 100755 --- a/update.py +++ b/update.py @@ -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=', 'Set the CMake build type (debug, release, or relwithdeb) [default: release].']) options.append(['--generator=', 'Set the CMake build system generator [default: Unix Makefiles].']) options.append(['--show', 'Show CMake command and exit.']) + options.append(['--cmake-options=', 'Define options to CMake [default: None].']) options.append(['', 'Build directory.']) options.append(['-h --help', 'Show this screen.'])