From dbfb61f9e2fd0150b8175d13231a008ecd17da25 Mon Sep 17 00:00:00 2001
From: Sergey Yakubov <sergey.yakubov@desy.de>
Date: Fri, 11 Dec 2020 13:37:50 +0100
Subject: [PATCH] refactor cmake files

---
 CMakeLists.txt                                |  8 ++++
 consumer/CMakeLists.txt                       |  5 ++-
 consumer/api/python/CMakeLists.txt            |  2 +-
 consumer/api/python/CMakeLists_Linux.cmake    |  8 ++--
 .../CMakeLists.txt                            | 38 +++++++++----------
 .../MANIFEST.in                               |  0
 .../setup.py.in                               |  0
 deploy/build_env/Ubuntu16.04/Dockerfile       |  9 +++--
 deploy/build_env/Ubuntu16.04/build.sh         | 10 +++--
 .../Ubuntu16.04/install_libfabric.sh          |  4 +-
 deploy/build_env/centos/build.sh              |  6 +--
 deploy/build_env/manylinux2010/build.sh       | 13 +++++--
 deploy/build_env/manylinux2010/build_image.sh | 11 ++++--
 docs/sphinx/CMakeLists.txt                    |  2 +-
 examples/consumer/CMakeLists.txt              |  4 +-
 .../getnext_broker_python/CMakeLists.txt      |  2 +-
 examples/pipeline/CMakeLists.txt              |  2 +-
 .../pipeline/in_to_out_python/CMakeLists.txt  |  2 +-
 producer/CMakeLists.txt                       |  5 ++-
 producer/api/python/CMakeLists.txt            |  2 +-
 producer/api/python/CMakeLists_Linux.cmake    |  7 ++--
 producer/api/python/CMakeLists_Windows.cmake  |  2 +-
 .../CMakeLists.txt                            | 19 ++++++----
 .../MANIFEST.in                               |  0
 .../setup.py.in                               |  0
 tests/automatic/bug_fixes/CMakeLists.txt      |  6 ++-
 .../consumer_python_memleak/CMakeLists.txt    |  2 +-
 tests/automatic/consumer/CMakeLists.txt       |  2 +-
 .../consumer_api_python/CMakeLists.txt        |  2 +-
 tests/automatic/full_chain/CMakeLists.txt     |  2 +-
 .../CMakeLists.txt                            |  2 +-
 .../CMakeLists.txt                            |  2 +-
 tests/automatic/producer/CMakeLists.txt       |  3 +-
 33 files changed, 109 insertions(+), 73 deletions(-)
 rename consumer/api/python/{source_dist_linux => dist_linux}/CMakeLists.txt (57%)
 rename consumer/api/python/{source_dist_linux => dist_linux}/MANIFEST.in (100%)
 rename consumer/api/python/{source_dist_linux => dist_linux}/setup.py.in (100%)
 rename producer/api/python/{source_dist_linux => dist_linux}/CMakeLists.txt (78%)
 rename producer/api/python/{source_dist_linux => dist_linux}/MANIFEST.in (100%)
 rename producer/api/python/{source_dist_linux => dist_linux}/setup.py.in (100%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b9d5114a5..f56f10d2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,6 +34,13 @@ option(BUILD_CLIENTS_ONLY "Build clients only" OFF)
 option(BUILD_CONSUMER_TOOLS "Build consumer tools" OFF)
 option(BUILD_EVENT_MONITOR_PRODUCER "Build the event monitor producer" OFF)
 
+option(BUILD_PYTHON "Build python libs" ON)
+if(BUILD_PYTHON)
+    set(BUILD_PYTHON_PACKAGES "" CACHE STRING "which python packages to build")
+    set_property(CACHE BUILD_PYTHON_PACKAGES PROPERTY STRINGS source rpm deb win)
+endif()
+
+
 option(BUILD_TESTS "Build unit tests" OFF)
 option(BUILD_INTEGRATION_TESTS "Include integration tests" OFF)
 
@@ -46,6 +53,7 @@ option(BUILD_PYTHON_DOCS "Build the Python documentaion with sphinx" OFF)
 option(ENABLE_LIBFABRIC "Enables LibFabric support for RDMA transfers" OFF)
 option(ENABLE_LIBFABRIC_LOCALHOST "Emulates LibFabric stack over TCP. Only for localhost and testing purposes." OFF)
 
+
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules/)
 
 set (ASAPO_CXX_COMMON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common/cpp/include)
diff --git a/consumer/CMakeLists.txt b/consumer/CMakeLists.txt
index b0bc14d1f..5fef2c2e3 100644
--- a/consumer/CMakeLists.txt
+++ b/consumer/CMakeLists.txt
@@ -1,5 +1,8 @@
 add_subdirectory(api/cpp)
-add_subdirectory(api/python)
+
+if (BUILD_PYTHON)
+    add_subdirectory(api/python)
+endif()
 
 
 if(BUILD_CONSUMER_TOOLS)
diff --git a/consumer/api/python/CMakeLists.txt b/consumer/api/python/CMakeLists.txt
index fa67bc779..3eeec3366 100644
--- a/consumer/api/python/CMakeLists.txt
+++ b/consumer/api/python/CMakeLists.txt
@@ -2,7 +2,7 @@
 if (UNIX)
     include(CMakeLists_Linux.cmake)
     set (suf "so")
-ELSEIF(CMAKE_BUILD_TYPE STREQUAL "Release")
+ELSE()
     set (suf "pyd")
     include(CMakeLists_Windows.cmake)
 ENDIF()
\ No newline at end of file
diff --git a/consumer/api/python/CMakeLists_Linux.cmake b/consumer/api/python/CMakeLists_Linux.cmake
index e0bbd7af0..c099a14d4 100644
--- a/consumer/api/python/CMakeLists_Linux.cmake
+++ b/consumer/api/python/CMakeLists_Linux.cmake
@@ -19,8 +19,10 @@ set (ASAPO_CONSUMER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../cpp/include)
 
 configure_files(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} @ONLY)
 
-ADD_CUSTOM_TARGET(python-lib COMMAND ${Python_EXECUTABLE} setup.py build_ext --inplace --force)
+ADD_CUSTOM_TARGET(python-lib-consumer ALL COMMAND ${Python_EXECUTABLE} setup.py build_ext --inplace --force)
 
-ADD_DEPENDENCIES(python-lib asapo-consumer)
+ADD_DEPENDENCIES(python-lib-consumer asapo-consumer)
 
-add_subdirectory(source_dist_linux)
+if (BUILD_PYTHON_PACKAGES)
+    add_subdirectory(dist_linux)
+endif()
diff --git a/consumer/api/python/source_dist_linux/CMakeLists.txt b/consumer/api/python/dist_linux/CMakeLists.txt
similarity index 57%
rename from consumer/api/python/source_dist_linux/CMakeLists.txt
rename to consumer/api/python/dist_linux/CMakeLists.txt
index 9c8c2d41b..67e5a6e9e 100644
--- a/consumer/api/python/source_dist_linux/CMakeLists.txt
+++ b/consumer/api/python/dist_linux/CMakeLists.txt
@@ -1,21 +1,26 @@
 configure_file(setup.py.in setup.py @ONLY)
 configure_file(MANIFEST.in MANIFEST.in @ONLY)
 
-ADD_CUSTOM_TARGET(python-dist
+if ("source" IN_LIST BUILD_PYTHON_PACKAGES )
+    ADD_CUSTOM_TARGET(python-dist-consumer ALL
         COMMAND ${Python_EXECUTABLE} setup.py sdist
         )
-
-ADD_CUSTOM_TARGET(python-rpm-consumer
-        COMMAND PACKAGE_PREFIX=python- python setup.py bdist_rpm --release=1.${PACKAGE_RELEASE_SUFFIX} --requires=numpy
-        )
-
-ADD_CUSTOM_TARGET(python3-rpm-consumer
-        COMMAND PACKAGE_PREFIX=python3- python3 setup.py bdist_rpm --release=1.${PACKAGE_RELEASE_SUFFIX} --requires=python3-numpy
-        )
-
-#get_property(ASAPO_CONSUMER_LIB TARGET asapo-consumer PROPERTY LOCATION)
-
-ADD_CUSTOM_TARGET(copy_python_dist
+    ADD_DEPENDENCIES(python-dist-consumer copy_python_dist-consumer)
+endif()
+
+if ("rpm" IN_LIST BUILD_PYTHON_PACKAGES)
+    ADD_CUSTOM_TARGET(python-rpm-consumer ALL
+            COMMAND PACKAGE_PREFIX=python- python setup.py bdist_rpm --release=1.${PACKAGE_RELEASE_SUFFIX} --requires=numpy
+            )
+
+    ADD_CUSTOM_TARGET(python3-rpm-consumer ALL
+            COMMAND PACKAGE_PREFIX=python3- python3 setup.py bdist_rpm --release=1.${PACKAGE_RELEASE_SUFFIX} --requires=python3-numpy
+            )
+    ADD_DEPENDENCIES(python-rpm-consumer copy_python_dist-consumer)
+    ADD_DEPENDENCIES(python3-rpm-consumer copy_python_dist-consumer)
+endif()
+
+ADD_CUSTOM_TARGET(copy_python_dist-consumer ALL
         COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../asapo_wrappers.h ${CMAKE_CURRENT_BINARY_DIR}/.
         COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../asapo_consumer.cpp ${CMAKE_CURRENT_BINARY_DIR}/.
         COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/consumer/api/cpp/include ${CMAKE_CURRENT_BINARY_DIR}/include
@@ -28,9 +33,4 @@ ADD_CUSTOM_TARGET(copy_python_dist
 
         )
 
-
-ADD_DEPENDENCIES(copy_python_dist python-lib)
-
-ADD_DEPENDENCIES(python-dist copy_python_dist)
-ADD_DEPENDENCIES(python-rpm-consumer python-dist)
-ADD_DEPENDENCIES(python3-rpm-consumer python-dist)
+ADD_DEPENDENCIES(copy_python_dist-consumer python-lib-consumer)
diff --git a/consumer/api/python/source_dist_linux/MANIFEST.in b/consumer/api/python/dist_linux/MANIFEST.in
similarity index 100%
rename from consumer/api/python/source_dist_linux/MANIFEST.in
rename to consumer/api/python/dist_linux/MANIFEST.in
diff --git a/consumer/api/python/source_dist_linux/setup.py.in b/consumer/api/python/dist_linux/setup.py.in
similarity index 100%
rename from consumer/api/python/source_dist_linux/setup.py.in
rename to consumer/api/python/dist_linux/setup.py.in
diff --git a/deploy/build_env/Ubuntu16.04/Dockerfile b/deploy/build_env/Ubuntu16.04/Dockerfile
index 20f8c8591..943b0329a 100644
--- a/deploy/build_env/Ubuntu16.04/Dockerfile
+++ b/deploy/build_env/Ubuntu16.04/Dockerfile
@@ -4,13 +4,16 @@ ENV GOPATH /tmp
 
 ADD install_curl.sh install_curl.sh
 ADD install_cmake.sh install_cmake.sh
-ADD install_libfabric.sh install_libfabric.sh
 
 RUN apt update && apt install -y g++ golang zlib1g-dev python cython python-numpy python3 cython3 python3-numpy  \
 git wget python-pip python3-pip && \
 pip  --no-cache-dir install --upgrade cython && pip3  --no-cache-dir install --upgrade cython && pip3  --no-cache-dir install sphinx && \
-./install_curl.sh /curl &&  ./install_cmake.sh && ./install_libfabric.sh \
-apt-get purge -y --auto-remove
+./install_curl.sh /curl &&  ./install_cmake.sh
+
+ADD install_libfabric.sh install_libfabric.sh
+RUN ./install_libfabric.sh
+
+RUN apt-get purge -y --auto-remove
 
 ADD build.sh /bin/build.sh
 
diff --git a/deploy/build_env/Ubuntu16.04/build.sh b/deploy/build_env/Ubuntu16.04/build.sh
index 54678561c..c0031edf8 100755
--- a/deploy/build_env/Ubuntu16.04/build.sh
+++ b/deploy/build_env/Ubuntu16.04/build.sh
@@ -8,9 +8,11 @@ cmake \
     -DENABLE_LIBFABRIC=on \
     -DLIBCURL_DIR=/curl \
     -DBUILD_PYTHON_DOCS=ON \
-    -DBUILD_EVENT_MONITOR_PRODUCER=ON \
+    -DBUILD_PYTHON_PACKAGES=source \
+    -DBUILD_CLIENTS_ONLY=ON \
     ..
-cd consumer/api/python/source_dist_linux && make python-dist
-cd ../producer/api/python/source_dist_linux && make python-dist-producer
-cd ../docs/sphinx && make
+make
+#cd consumer/api/python/dist_linux && make python-dist-consumer
+#cd ../producer/api/python/dist_linux && make python-dist-producer
+#cd ../docs/sphinx && make
 
diff --git a/deploy/build_env/Ubuntu16.04/install_libfabric.sh b/deploy/build_env/Ubuntu16.04/install_libfabric.sh
index a6ef6db45..ecfc8cdb6 100755
--- a/deploy/build_env/Ubuntu16.04/install_libfabric.sh
+++ b/deploy/build_env/Ubuntu16.04/install_libfabric.sh
@@ -1,8 +1,10 @@
 #!/usr/bin/env bash
 
-apt install -y wget autoconf libtool make librdmacm-dev rdma-core
 wget https://github.com/ofiwg/libfabric/archive/v1.11.0.tar.gz
 tar xzf v1.11.0.tar.gz
+
+apt install -y autoconf libtool make librdmacm-dev mc
+
 cd libfabric-1.11.0
 ./autogen.sh
 ./configure
diff --git a/deploy/build_env/centos/build.sh b/deploy/build_env/centos/build.sh
index dbcfc1ccc..9ca1c74d7 100755
--- a/deploy/build_env/centos/build.sh
+++ b/deploy/build_env/centos/build.sh
@@ -7,12 +7,12 @@ cmake \
     -DINSTALL_EXAMPLES=ON \
     -DBUILD_CLIENTS_ONLY=ON \
     -DPACKAGE_RELEASE_SUFFIX=$OS \
-    -DNUMPY_VERSION=0   \
+    -DBUILD_PYTHON=OFF   \
     -DLIBCURL_DIR=/curl \
     ..
 make
 make package
-cd consumer/api/python/source_dist_linux && make python-rpm-consumer python3-rpm-consumer && cd -
-cd producer/api/python/source_dist_linux && make python-rpm-producer python3-rpm-producer
 
+cmake -DNUMPY_VERSION=0 -DBUILD_PYTHON=ON -DBUILD_PYTHON_PACKAGES="source;rpm" ..
+make
 
diff --git a/deploy/build_env/manylinux2010/build.sh b/deploy/build_env/manylinux2010/build.sh
index 586cd0486..0fee6f1fa 100755
--- a/deploy/build_env/manylinux2010/build.sh
+++ b/deploy/build_env/manylinux2010/build.sh
@@ -18,12 +18,17 @@ for python_path in /opt/python/cp{27,35,36,37,38}*; do
     echo "building wheel for python_version=$python_version with numpy_version=$numpy_version"
 
     cd /asapo/build
-    cmake -DENABLE_LIBFABRIC=on -DCMAKE_BUILD_TYPE="Release" -DLIBCURL_DIR=/curl -DPython_EXECUTABLE=$python -DNUMPY_VERSION=$numpy_version ..
-    cd /asapo/build/consumer/api/python/source_dist_linux \
+    cmake -DENABLE_LIBFABRIC=on \
+          -DCMAKE_BUILD_TYPE="Release" \
+          -DBUILD_CLIENTS_ONLY=ON \
+          -DLIBCURL_DIR=/curl -DPython_EXECUTABLE=$python \
+          -DBUILD_PYTHON_PACKAGES=source \
+          -DNUMPY_VERSION=$numpy_version ..
+    cd /asapo/build/consumer/api/python/dist_linux \
         && $pip install -r ../dev-requirements.txt \
-        && make python-dist \
+        && make python-dist-consumer \
         && $pip wheel dist/*.tar.gz -w /asapo/build/consumer/wheelhouse --no-deps
-    cd  /asapo/build/producer/api/python/source_dist_linux \
+    cd  /asapo/build/producer/api/python/dist_linux \
         && $pip install -r ../dev-requirements.txt \
         && make python-dist-producer \
         && $pip wheel dist/*.tar.gz -w /asapo/build/producer/wheelhouse --no-deps
diff --git a/deploy/build_env/manylinux2010/build_image.sh b/deploy/build_env/manylinux2010/build_image.sh
index d5667a514..ed3fc8061 100755
--- a/deploy/build_env/manylinux2010/build_image.sh
+++ b/deploy/build_env/manylinux2010/build_image.sh
@@ -1,6 +1,11 @@
 #!/usr/bin/env bash
 
-docker build -t yakser/asapo-env:manylinux2010_ .
-./docker-squash yakser/asapo-env:manylinux2010_ -t yakser/asapo-env:manylinux2010
-docker push yakser/asapo-env:manylinux2010
+#docker build -t yakser/asapo-env:manylinux2010_ .
+#./docker-squash yakser/asapo-env:manylinux2010_ -t yakser/asapo-env:manylinux2010
+
+docker build -t yakser/asapo-env:manylinux2010 .
+#docker push yakser/asapo-env:manylinux2010
+#docker push yakser/asapo-env:manylinux2010
+
+
 
diff --git a/docs/sphinx/CMakeLists.txt b/docs/sphinx/CMakeLists.txt
index 77fda050e..9da6590e7 100644
--- a/docs/sphinx/CMakeLists.txt
+++ b/docs/sphinx/CMakeLists.txt
@@ -9,4 +9,4 @@ add_custom_target(
 )
 
 add_dependencies(docs-py python-lib-producer)
-add_dependencies(docs-py python-lib)
+add_dependencies(docs-py python-lib-consumer)
diff --git a/examples/consumer/CMakeLists.txt b/examples/consumer/CMakeLists.txt
index 6da6f7a60..1bb3170d2 100644
--- a/examples/consumer/CMakeLists.txt
+++ b/examples/consumer/CMakeLists.txt
@@ -2,10 +2,8 @@ find_package(Threads)
 
 add_subdirectory(getnext_broker)
 
-if(BUILD_EXAMPLES)
-    if (UNIX OR CMAKE_BUILD_TYPE STREQUAL "Release")
+if(BUILD_EXAMPLES AND BUILD_PYTHON)
         add_subdirectory(getnext_broker_python)
-    endif()
 endif()
 
 
diff --git a/examples/consumer/getnext_broker_python/CMakeLists.txt b/examples/consumer/getnext_broker_python/CMakeLists.txt
index f0a26a43e..22bd7bea6 100644
--- a/examples/consumer/getnext_broker_python/CMakeLists.txt
+++ b/examples/consumer/getnext_broker_python/CMakeLists.txt
@@ -4,7 +4,7 @@ set(TARGET_NAME getnext_broker_python)
 prepare_asapo()
 
 if (UNIX)
-    get_target_property(PYTHON_LIBS python-lib BINARY_DIR)
+    get_target_property(PYTHON_LIBS python-lib-consumer BINARY_DIR)
 else()
     get_target_property(PYTHON_LIBS asapo_consumer BINARY_DIR)
 endif()
diff --git a/examples/pipeline/CMakeLists.txt b/examples/pipeline/CMakeLists.txt
index 8dce2cc37..c11f2d30e 100644
--- a/examples/pipeline/CMakeLists.txt
+++ b/examples/pipeline/CMakeLists.txt
@@ -1,6 +1,6 @@
 
 add_subdirectory(in_to_out)
 
-if (UNIX OR CMAKE_BUILD_TYPE STREQUAL "Release")
+if (BUILD_PYTHON)
     add_subdirectory(in_to_out_python)
 endif()
diff --git a/examples/pipeline/in_to_out_python/CMakeLists.txt b/examples/pipeline/in_to_out_python/CMakeLists.txt
index 9ab39455b..cebedb3f7 100644
--- a/examples/pipeline/in_to_out_python/CMakeLists.txt
+++ b/examples/pipeline/in_to_out_python/CMakeLists.txt
@@ -3,7 +3,7 @@ set(TARGET_NAME pipeline_inout_python)
 prepare_asapo()
 
 if (UNIX)
-    get_target_property(PYTHON_LIBS_CONSUMER python-lib BINARY_DIR)
+    get_target_property(PYTHON_LIBS_CONSUMER python-lib-consumer BINARY_DIR)
     get_target_property(PYTHON_LIBS_PRODUCER python-lib-producer BINARY_DIR)
 else()
     get_target_property(PYTHON_LIBS_CONSUMER asapo_consumer BINARY_DIR)
diff --git a/producer/CMakeLists.txt b/producer/CMakeLists.txt
index 3c8560c15..dea86005c 100644
--- a/producer/CMakeLists.txt
+++ b/producer/CMakeLists.txt
@@ -1,5 +1,8 @@
 add_subdirectory(api/cpp)
-add_subdirectory(api/python)
+
+if (BUILD_PYTHON)
+    add_subdirectory(api/python)
+endif()
 
 if(BUILD_EVENT_MONITOR_PRODUCER)
     add_subdirectory(event_monitor_producer)
diff --git a/producer/api/python/CMakeLists.txt b/producer/api/python/CMakeLists.txt
index fa67bc779..3eeec3366 100644
--- a/producer/api/python/CMakeLists.txt
+++ b/producer/api/python/CMakeLists.txt
@@ -2,7 +2,7 @@
 if (UNIX)
     include(CMakeLists_Linux.cmake)
     set (suf "so")
-ELSEIF(CMAKE_BUILD_TYPE STREQUAL "Release")
+ELSE()
     set (suf "pyd")
     include(CMakeLists_Windows.cmake)
 ENDIF()
\ No newline at end of file
diff --git a/producer/api/python/CMakeLists_Linux.cmake b/producer/api/python/CMakeLists_Linux.cmake
index 47bee3561..de40245e9 100644
--- a/producer/api/python/CMakeLists_Linux.cmake
+++ b/producer/api/python/CMakeLists_Linux.cmake
@@ -14,10 +14,11 @@ set (ASAPO_PRODUCER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../cpp/include)
 configure_files(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} @ONLY)
 file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/setup.py INPUT ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
 
-
-ADD_CUSTOM_TARGET(python-lib-producer
+ADD_CUSTOM_TARGET(python-lib-producer ALL
         COMMAND ${Python_EXECUTABLE} setup.py build_ext --inplace --force)
 
 ADD_DEPENDENCIES(python-lib-producer asapo-producer)
 
-add_subdirectory(source_dist_linux)
+if (BUILD_PYTHON_PACKAGES)
+    add_subdirectory(dist_linux)
+endif()
diff --git a/producer/api/python/CMakeLists_Windows.cmake b/producer/api/python/CMakeLists_Windows.cmake
index 955c52966..009a0a7c5 100644
--- a/producer/api/python/CMakeLists_Windows.cmake
+++ b/producer/api/python/CMakeLists_Windows.cmake
@@ -31,4 +31,4 @@ add_subdirectory(binary_dist_windows)
 
 set (EXTRA_COMPILE_ARGS "['/MT']")
 set (EXTRA_LINK_ARGS "[]")
-add_subdirectory(source_dist_linux)
+add_subdirectory(dist_linux)
diff --git a/producer/api/python/source_dist_linux/CMakeLists.txt b/producer/api/python/dist_linux/CMakeLists.txt
similarity index 78%
rename from producer/api/python/source_dist_linux/CMakeLists.txt
rename to producer/api/python/dist_linux/CMakeLists.txt
index 1ee0b4ff1..654c4a611 100644
--- a/producer/api/python/source_dist_linux/CMakeLists.txt
+++ b/producer/api/python/dist_linux/CMakeLists.txt
@@ -3,19 +3,26 @@ configure_file(MANIFEST.in MANIFEST.in @ONLY)
 
 file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/setup.py INPUT ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
 
-ADD_CUSTOM_TARGET(python-rpm-producer
+if ("rpm" IN_LIST BUILD_PYTHON_PACKAGES)
+	ADD_CUSTOM_TARGET(python-rpm-producer ALL
 		COMMAND PACKAGE_PREFIX=python- python setup.py bdist_rpm --release=1.${PACKAGE_RELEASE_SUFFIX} --requires=numpy
 		)
 
-ADD_CUSTOM_TARGET(python3-rpm-producer
+	ADD_CUSTOM_TARGET(python3-rpm-producer ALL
 		COMMAND PACKAGE_PREFIX=python3- python3 setup.py bdist_rpm --release=1.${PACKAGE_RELEASE_SUFFIX} --requires=python3-numpy
 		)
+	ADD_DEPENDENCIES(python3-rpm-producer copy_python_dist-producer)
+	ADD_DEPENDENCIES(python-rpm-producer copy_python_dist-producer)
+endif()
 
-ADD_CUSTOM_TARGET(python-dist-producer
+if ("source" IN_LIST BUILD_PYTHON_PACKAGES )
+	ADD_CUSTOM_TARGET(python-dist-producer ALL
         COMMAND ${Python_EXECUTABLE} setup.py sdist
         )
+	ADD_DEPENDENCIES(python-dist-producer copy_python_dist-producer)
+endif()
 
-ADD_CUSTOM_TARGET(copy_python_dist-producer
+ADD_CUSTOM_TARGET(copy_python_dist-producer ALL
         COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../asapo_wrappers.h ${CMAKE_CURRENT_BINARY_DIR}/.
         COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../asapo_producer.cpp ${CMAKE_CURRENT_BINARY_DIR}/.
         COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/producer/api/cpp/include ${CMAKE_CURRENT_BINARY_DIR}/include
@@ -27,13 +34,9 @@ ADD_CUSTOM_TARGET(copy_python_dist-producer
         COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:asapo-producer> ${CMAKE_CURRENT_BINARY_DIR}/lib
         )
 
-
 if (UNIX)
 	ADD_DEPENDENCIES(copy_python_dist-producer python-lib-producer)
 ELSE()
 	ADD_DEPENDENCIES(copy_python_dist-producer asapo_producer)
 ENDIF()
 
-ADD_DEPENDENCIES(python-dist-producer copy_python_dist-producer)
-ADD_DEPENDENCIES(python3-rpm-producer copy_python_dist-producer)
-ADD_DEPENDENCIES(python-rpm-producer copy_python_dist-producer)
diff --git a/producer/api/python/source_dist_linux/MANIFEST.in b/producer/api/python/dist_linux/MANIFEST.in
similarity index 100%
rename from producer/api/python/source_dist_linux/MANIFEST.in
rename to producer/api/python/dist_linux/MANIFEST.in
diff --git a/producer/api/python/source_dist_linux/setup.py.in b/producer/api/python/dist_linux/setup.py.in
similarity index 100%
rename from producer/api/python/source_dist_linux/setup.py.in
rename to producer/api/python/dist_linux/setup.py.in
diff --git a/tests/automatic/bug_fixes/CMakeLists.txt b/tests/automatic/bug_fixes/CMakeLists.txt
index 35f942b1a..17a66a524 100644
--- a/tests/automatic/bug_fixes/CMakeLists.txt
+++ b/tests/automatic/bug_fixes/CMakeLists.txt
@@ -1,7 +1,9 @@
 if (UNIX)
     add_subdirectory(receiver_cpu_usage)
-    add_subdirectory(consumer_python_memleak)
-    add_subdirectory(error-sending-data-using-callback-method)
+    if (BUILD_PYTHON)
+        add_subdirectory(consumer_python_memleak)
+        add_subdirectory(error-sending-data-using-callback-method)
+    endif()
 endif()
 
 add_subdirectory(producer_send_after_restart)
diff --git a/tests/automatic/bug_fixes/consumer_python_memleak/CMakeLists.txt b/tests/automatic/bug_fixes/consumer_python_memleak/CMakeLists.txt
index 6c6b66006..352d76a2b 100644
--- a/tests/automatic/bug_fixes/consumer_python_memleak/CMakeLists.txt
+++ b/tests/automatic/bug_fixes/consumer_python_memleak/CMakeLists.txt
@@ -4,7 +4,7 @@ set(TARGET_NAME consumer_python_memleak)
 prepare_asapo()
 
 if (UNIX)
-    get_target_property(PYTHON_LIBS python-lib BINARY_DIR)
+    get_target_property(PYTHON_LIBS python-lib-consumer BINARY_DIR)
 else()
     get_target_property(PYTHON_LIBS asapo_consumer BINARY_DIR)
 endif()
diff --git a/tests/automatic/consumer/CMakeLists.txt b/tests/automatic/consumer/CMakeLists.txt
index 1d4de1fa0..50c68fda8 100644
--- a/tests/automatic/consumer/CMakeLists.txt
+++ b/tests/automatic/consumer/CMakeLists.txt
@@ -3,7 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.7) # needed for fixtures
 add_subdirectory(next_multithread_broker)
 add_subdirectory(consumer_api)
 
-if (UNIX OR CMAKE_BUILD_TYPE STREQUAL "Release")
+if (BUILD_PYTHON)
     add_subdirectory(consumer_api_python)
 endif()
 
diff --git a/tests/automatic/consumer/consumer_api_python/CMakeLists.txt b/tests/automatic/consumer/consumer_api_python/CMakeLists.txt
index f63e4734a..a4afb1b75 100644
--- a/tests/automatic/consumer/consumer_api_python/CMakeLists.txt
+++ b/tests/automatic/consumer/consumer_api_python/CMakeLists.txt
@@ -4,7 +4,7 @@ set(TARGET_NAME consumer_api_python)
 prepare_asapo()
 
 if (UNIX)
-    get_target_property(PYTHON_LIBS python-lib BINARY_DIR)
+    get_target_property(PYTHON_LIBS python-lib-consumer BINARY_DIR)
 else()
     get_target_property(PYTHON_LIBS asapo_consumer BINARY_DIR)
 endif()
diff --git a/tests/automatic/full_chain/CMakeLists.txt b/tests/automatic/full_chain/CMakeLists.txt
index 958cfce30..0d7dd8b9f 100644
--- a/tests/automatic/full_chain/CMakeLists.txt
+++ b/tests/automatic/full_chain/CMakeLists.txt
@@ -1,5 +1,5 @@
 add_subdirectory(simple_chain)
-if (UNIX OR CMAKE_BUILD_TYPE STREQUAL "Release")
+if (BUILD_PYTHON)
     add_subdirectory(simple_chain_usermeta_python)
     add_subdirectory(send_recv_substreams_python)
 endif()
diff --git a/tests/automatic/full_chain/send_recv_substreams_python/CMakeLists.txt b/tests/automatic/full_chain/send_recv_substreams_python/CMakeLists.txt
index 26c975030..7a5de77a6 100644
--- a/tests/automatic/full_chain/send_recv_substreams_python/CMakeLists.txt
+++ b/tests/automatic/full_chain/send_recv_substreams_python/CMakeLists.txt
@@ -2,7 +2,7 @@ set(TARGET_NAME send_recv_substreams_python)
 prepare_asapo()
 
 if (UNIX)
-    get_target_property(PYTHON_LIBS_CONSUMER python-lib BINARY_DIR)
+    get_target_property(PYTHON_LIBS_CONSUMER python-lib-consumer BINARY_DIR)
     get_target_property(PYTHON_LIBS_PRODUCER python-lib-producer BINARY_DIR)
 else()
     get_target_property(PYTHON_LIBS_CONSUMER asapo_consumer BINARY_DIR)
diff --git a/tests/automatic/full_chain/simple_chain_usermeta_python/CMakeLists.txt b/tests/automatic/full_chain/simple_chain_usermeta_python/CMakeLists.txt
index 956e8dea6..827a81a9c 100644
--- a/tests/automatic/full_chain/simple_chain_usermeta_python/CMakeLists.txt
+++ b/tests/automatic/full_chain/simple_chain_usermeta_python/CMakeLists.txt
@@ -6,7 +6,7 @@ set(TARGET_NAME full_chain_usermeta_python)
 prepare_asapo()
 
 if (UNIX)
-    get_target_property(PYTHON_LIBS python-lib BINARY_DIR)
+    get_target_property(PYTHON_LIBS python-lib-consumer BINARY_DIR)
 else()
     get_target_property(PYTHON_LIBS asapo_consumer BINARY_DIR)
 endif()
diff --git a/tests/automatic/producer/CMakeLists.txt b/tests/automatic/producer/CMakeLists.txt
index e96695ebb..3f9a65756 100644
--- a/tests/automatic/producer/CMakeLists.txt
+++ b/tests/automatic/producer/CMakeLists.txt
@@ -1,8 +1,7 @@
 add_subdirectory(file_monitor_producer)
 add_subdirectory(beamtime_metadata)
 
-if (UNIX OR CMAKE_BUILD_TYPE STREQUAL "Release")
+if (BUILD_PYTHON)
     add_subdirectory(python_api)
     add_subdirectory(aai)
-
 endif()
-- 
GitLab