From d7063a410c8c1553244414da548da3efdef863eb Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Tue, 5 May 2020 15:58:49 +0200
Subject: [PATCH] Update in CMake machinery for new Python_FOUND variable style

---
 Core/CMakeLists.txt                             | 10 +++++-----
 Fit/CMakeLists.txt                              |  6 +++---
 Tests/Functional/Python/PyCore/CMakeLists.txt   |  2 +-
 .../Functional/Python/PyEmbedded/CMakeLists.txt |  4 ++--
 .../Functional/Python/PyEmbedded/TestCases.cpp  |  3 ++-
 .../Functional/Python/PyExamples/CMakeLists.txt |  2 +-
 Tests/Functional/Python/PyFit/CMakeLists.txt    |  2 +-
 .../Python/PyPersistence/CMakeLists.txt         |  2 +-
 cmake/bornagain/modules/CPackApple.cmake        |  2 +-
 cmake/bornagain/modules/CPackWindows.cmake      |  2 +-
 cmake/bornagain/modules/CheckCode.cmake         |  2 +-
 cmake/bornagain/modules/FixAppleBundle.cmake.in |  2 +-
 .../bornagain/modules/GeneratePythonDocs.cmake  |  2 +-
 .../modules/PyExamplesLineLength.cmake          |  2 +-
 cmake/bornagain/scripts/BABuild.h.in            | 17 +++++++++--------
 15 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt
index 9e4d7c26daa..21f630add94 100644
--- a/Core/CMakeLists.txt
+++ b/Core/CMakeLists.txt
@@ -68,7 +68,7 @@ if(BORNAGAIN_PYTHON)
 
         add_custom_command (
             OUTPUT ${AUTO_DIR}/libBornAgainCore.py
-            COMMAND ${PYTHON_EXECUTABLE} ${WRAP_DIR}/swig/tweaks.py
+            COMMAND ${Python_EXECUTABLE} ${WRAP_DIR}/swig/tweaks.py
                    ${TMP_DIR}/libBornAgainCore.py
                    ${AUTO_DIR}/libBornAgainCore.py
             DEPENDS ${TMP_DIR}/libBornAgainCore.py
@@ -166,8 +166,8 @@ endif()
 
 if(BORNAGAIN_PYTHON)
     target_compile_definitions(${library_name} PUBLIC -DBORNAGAIN_PYTHON)
-    include_directories(${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR})
-    target_link_libraries(${library_name} ${PYTHON_LIBRARIES})
+    include_directories(${Python_INCLUDE_DIRS} ${Python_NumPy_INCLUDE_DIRS})
+    target_link_libraries(${library_name} ${Python_LIBRARIES})
 endif()
 
 if(APPLE AND BORNAGAIN_APPLE_BUNDLE)
@@ -220,8 +220,8 @@ if(WIN32)
             DESTINATION ${destination_lib} COMPONENT Libraries)
     endforeach()
 
-    get_filename_component(UTF_BASE_NAME ${PYTHON_LIBRARIES} NAME_WE)
-    get_filename_component(UTF_PATH ${PYTHON_EXECUTABLE} PATH)
+    get_filename_component(UTF_BASE_NAME ${Python_LIBRARIES} NAME_WE)
+    get_filename_component(UTF_PATH ${Python_EXECUTABLE} PATH)
     message(STATUS "Python dll: ${UTF_PATH}/${UTF_BASE_NAME}.dll")
     install(FILES ${UTF_PATH}/${UTF_BASE_NAME}.dll
         DESTINATION ${destination_lib} COMPONENT Libraries)
diff --git a/Fit/CMakeLists.txt b/Fit/CMakeLists.txt
index 15eb01ae5a0..571b3fb2f42 100644
--- a/Fit/CMakeLists.txt
+++ b/Fit/CMakeLists.txt
@@ -56,7 +56,7 @@ if(BORNAGAIN_PYTHON)
 
         add_custom_command (
             OUTPUT ${AUTO_DIR}/libBornAgainFit.py
-            COMMAND ${PYTHON_EXECUTABLE} ${WRAP_DIR}/swig/tweaks.py
+            COMMAND ${Python_EXECUTABLE} ${WRAP_DIR}/swig/tweaks.py
                    ${TMP_DIR}/libBornAgainFit.py
                    ${AUTO_DIR}/libBornAgainFit.py
             DEPENDS ${TMP_DIR}/libBornAgainFit.py
@@ -109,8 +109,8 @@ target_include_directories(${library_name} PUBLIC ${include_dirs})
 target_link_libraries(${library_name} ${RootMinimizers_LIBRARY}  ${Boost_LIBRARIES})
 
 if(BORNAGAIN_PYTHON)
-    include_directories(${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR})
-    target_link_libraries(${library_name} ${PYTHON_LIBRARIES})
+    include_directories(${Python_INCLUDE_DIRS} ${Python_NumPy_INCLUDE_DIRS})
+    target_link_libraries(${library_name} ${Python_LIBRARIES})
 endif()
 
 # --- custom actions
diff --git a/Tests/Functional/Python/PyCore/CMakeLists.txt b/Tests/Functional/Python/PyCore/CMakeLists.txt
index 479c0fdd2cc..aaf1843b62e 100644
--- a/Tests/Functional/Python/PyCore/CMakeLists.txt
+++ b/Tests/Functional/Python/PyCore/CMakeLists.txt
@@ -21,5 +21,5 @@ set(tests ${sources})
 list(REMOVE_ITEM tests utils.py)
 
 foreach(_test ${tests})
-    add_test(PyCore/${_test} ${PYTHON_EXECUTABLE} ${OUTPUT_DIR}/${_test})
+    add_test(PyCore/${_test} ${Python_EXECUTABLE} ${OUTPUT_DIR}/${_test})
 endforeach()
diff --git a/Tests/Functional/Python/PyEmbedded/CMakeLists.txt b/Tests/Functional/Python/PyEmbedded/CMakeLists.txt
index 3987082243a..ceda8dbbe79 100644
--- a/Tests/Functional/Python/PyEmbedded/CMakeLists.txt
+++ b/Tests/Functional/Python/PyEmbedded/CMakeLists.txt
@@ -13,8 +13,8 @@ set(test_cases
 )
 
 include_directories(
-    ${PYTHON_INCLUDE_DIRS}
-    ${NUMPY_INCLUDE_DIR}
+    ${Python_INCLUDE_DIRS}
+    ${Python_NumPy_INCLUDE_DIRS}
     ${CMAKE_SOURCE_DIR}/auto/Wrap
 )
 
diff --git a/Tests/Functional/Python/PyEmbedded/TestCases.cpp b/Tests/Functional/Python/PyEmbedded/TestCases.cpp
index f70b9d10a4e..693612ba9d0 100644
--- a/Tests/Functional/Python/PyEmbedded/TestCases.cpp
+++ b/Tests/Functional/Python/PyEmbedded/TestCases.cpp
@@ -33,10 +33,11 @@ bool SysPath::runTest()
 {
     // Python build info
     std::cout << "pythonExecutable(): " << BABuild::pythonExecutable() << std::endl;
+    std::cout << "pythonInterpreterID(): " << BABuild::pythonInterpreterID() << std::endl;
     std::cout << "pythonVersionString(): " << BABuild::pythonVersionString() << std::endl;
     std::cout << "pythonLibraries(): " << BABuild::pythonLibraries() << std::endl;
     std::cout << "pythonIncludeDirs(): " << BABuild::pythonIncludeDirs() << std::endl;
-    std::cout << "pythonLibsVersionString(): " << BABuild::pythonLibsVersionString() << std::endl;
+    std::cout << "pythonSiteLib(): " << BABuild::pythonSiteLib() << std::endl;
     std::cout << "numpyIncludeDir(): " << BABuild::numpyIncludeDir() << std::endl;
     std::cout << "numpyVersionString(): " << BABuild::numpyVersionString() << std::endl;
 
diff --git a/Tests/Functional/Python/PyExamples/CMakeLists.txt b/Tests/Functional/Python/PyExamples/CMakeLists.txt
index dcc0c026176..3fbb476bd35 100644
--- a/Tests/Functional/Python/PyExamples/CMakeLists.txt
+++ b/Tests/Functional/Python/PyExamples/CMakeLists.txt
@@ -24,6 +24,6 @@ foreach(example ${examples})
     get_filename_component(script_name ${script_path} NAME_WE)
     set(test_name PyExamples/${script_name})
 
-    add_test(${test_name} ${PYTHON_EXECUTABLE} ${test_script} ${script_path})
+    add_test(${test_name} ${Python_EXECUTABLE} ${test_script} ${script_path})
     set_tests_properties(${test_name} PROPERTIES LABELS "Fullcheck")
 endforeach()
diff --git a/Tests/Functional/Python/PyFit/CMakeLists.txt b/Tests/Functional/Python/PyFit/CMakeLists.txt
index 72a470992eb..e68bc82b958 100644
--- a/Tests/Functional/Python/PyFit/CMakeLists.txt
+++ b/Tests/Functional/Python/PyFit/CMakeLists.txt
@@ -18,5 +18,5 @@ set(tests
 )
 
 foreach(_test ${tests})
-    add_test(PyFit/${_test} ${PYTHON_EXECUTABLE}  ${output_dir}/${_test})
+    add_test(PyFit/${_test} ${Python_EXECUTABLE}  ${output_dir}/${_test})
 endforeach()
diff --git a/Tests/Functional/Python/PyPersistence/CMakeLists.txt b/Tests/Functional/Python/PyPersistence/CMakeLists.txt
index c7aabf2a3a0..e407c7d8e49 100644
--- a/Tests/Functional/Python/PyPersistence/CMakeLists.txt
+++ b/Tests/Functional/Python/PyPersistence/CMakeLists.txt
@@ -21,7 +21,7 @@ function(test_example example tolerance)
     set(example_mod ${OUTPUT_DIR}/${EXAMPLE_NAME}_mod.py)
     configure_file(example_template.py ${example_mod} @ONLY)
 
-    add_test(${test_name} ${PYTHON_EXECUTABLE} "-B" "${example_mod}")
+    add_test(${test_name} ${Python_EXECUTABLE} "-B" "${example_mod}")
 endfunction()
 
 test_example("simulation/ex01_BasicParticles/CylindersAndPrisms" 2e-10)
diff --git a/cmake/bornagain/modules/CPackApple.cmake b/cmake/bornagain/modules/CPackApple.cmake
index f19dac116ac..715e8d2971d 100644
--- a/cmake/bornagain/modules/CPackApple.cmake
+++ b/cmake/bornagain/modules/CPackApple.cmake
@@ -1,6 +1,6 @@
 # BornAgain Mac packaging 
 
-set(SELECTED_PYTHON_VERSION "python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
+set(SELECTED_PYTHON_VERSION "python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")
 
 set(CPACK_PACKAGE_FILE_NAME
     "${CMAKE_PROJECT_NAME}-${BORNAGAIN_VERSION}-${SELECTED_PYTHON_VERSION}-${BORNAGAIN_ARCHITECTURE}-10.10+")
diff --git a/cmake/bornagain/modules/CPackWindows.cmake b/cmake/bornagain/modules/CPackWindows.cmake
index 91705c836ab..880476ea856 100644
--- a/cmake/bornagain/modules/CPackWindows.cmake
+++ b/cmake/bornagain/modules/CPackWindows.cmake
@@ -1,6 +1,6 @@
 # BornAgain Windows packaging
 
-set(SELECTED_PYTHON_VERSION "python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
+set(SELECTED_PYTHON_VERSION "python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")
 
 set(CPACK_PACKAGE_FILE_NAME
     "${CMAKE_PROJECT_NAME}-${BORNAGAIN_VERSION}-${SELECTED_PYTHON_VERSION}-${BORNAGAIN_ARCHITECTURE}")
diff --git a/cmake/bornagain/modules/CheckCode.cmake b/cmake/bornagain/modules/CheckCode.cmake
index 29b413952dd..09e4da1d493 100644
--- a/cmake/bornagain/modules/CheckCode.cmake
+++ b/cmake/bornagain/modules/CheckCode.cmake
@@ -10,7 +10,7 @@ if(NOT MSVC)
 #   file(GLOB_RECURSE SRC2 "GUI/*.h")
 
     add_test(NAME "CodeLineLength"
-        COMMAND ${PYTHON_EXECUTABLE}
+        COMMAND ${Python_EXECUTABLE}
         ${CMAKE_SOURCE_DIR}/dev-tools/analyze/check-line-length.py ${SRC_LEN_LIM}
         ${SRC1} ${SRC2})
 endif()
diff --git a/cmake/bornagain/modules/FixAppleBundle.cmake.in b/cmake/bornagain/modules/FixAppleBundle.cmake.in
index c4fbfb46f46..87e9d1a6eb7 100644
--- a/cmake/bornagain/modules/FixAppleBundle.cmake.in
+++ b/cmake/bornagain/modules/FixAppleBundle.cmake.in
@@ -3,4 +3,4 @@
 ###############################################################################
 
 set(bundle ${CMAKE_INSTALL_PREFIX}/BornAgain.app )
-execute_process(COMMAND @PYTHON_EXECUTABLE@ @CMAKE_SOURCE_DIR@/cmake/bornagain/scripts/fix_apple_bundle.py ${bundle})
+execute_process(COMMAND @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/cmake/bornagain/scripts/fix_apple_bundle.py ${bundle})
diff --git a/cmake/bornagain/modules/GeneratePythonDocs.cmake b/cmake/bornagain/modules/GeneratePythonDocs.cmake
index 85497ae9674..c7f360e20d9 100644
--- a/cmake/bornagain/modules/GeneratePythonDocs.cmake
+++ b/cmake/bornagain/modules/GeneratePythonDocs.cmake
@@ -12,7 +12,7 @@ function(GeneratePythonDocs PD_TARGET SWIG_DIR)
             )
         add_custom_command(
             OUTPUT ${PD_TARGET}
-            COMMAND ${PYTHON_EXECUTABLE} ${SWIG_DIR}/doxy2swig.py
+            COMMAND ${Python_EXECUTABLE} ${SWIG_DIR}/doxy2swig.py
             ${TMP_DIR}/xml/index.xml ${PD_TARGET}
             DEPENDS ${TMP_DIR}/xml/index.xml
             )
diff --git a/cmake/bornagain/modules/PyExamplesLineLength.cmake b/cmake/bornagain/modules/PyExamplesLineLength.cmake
index 60dbf1cb4f7..7894d9fea16 100644
--- a/cmake/bornagain/modules/PyExamplesLineLength.cmake
+++ b/cmake/bornagain/modules/PyExamplesLineLength.cmake
@@ -6,7 +6,7 @@ if(NOT MSVC)
 
 file(GLOB PY_EXAMPLES "${PY_EXAMPLES_DIR}/*/ex*/*.py")
 
-add_test(NAME "PyExamplesLineLength" COMMAND ${PYTHON_EXECUTABLE}
+add_test(NAME "PyExamplesLineLength" COMMAND ${Python_EXECUTABLE}
     ${CMAKE_SOURCE_DIR}/dev-tools/analyze/check-line-length.py ${WEB_LEN_LIM}
     ${PY_EXAMPLES})
 
diff --git a/cmake/bornagain/scripts/BABuild.h.in b/cmake/bornagain/scripts/BABuild.h.in
index cca67fc60b5..67c16cf5650 100644
--- a/cmake/bornagain/scripts/BABuild.h.in
+++ b/cmake/bornagain/scripts/BABuild.h.in
@@ -27,14 +27,15 @@ inline std::string buildBinDir() { return "@CMAKE_BINARY_DIR@/bin"; }
 
 //! Methods to access info about Python used during the build.
 
-inline std::string pythonExecutable() { return "@PYTHON_EXECUTABLE@"; }
-inline std::string pythonVersionString() { return "@PYTHON_VERSION_STRING@"; }
-inline std::string pythonLibraries() { return "@PYTHON_LIBRARIES@"; }
-inline std::string pythonIncludeDirs() { return "@PYTHON_INCLUDE_DIRS@"; }
-inline std::string pythonLibsVersionString() { return "@PYTHONLIBS_VERSION_STRING@"; }
-inline std::string numpyIncludeDir() { return "@NUMPY_INCLUDE_DIR@"; }
-inline std::string numpyVersionString() { return "@NUMPY_VERSION_STRING@"; }
-
+inline std::string pythonExecutable() { return "@Python_EXECUTABLE@"; }
+inline std::string pythonInterpreterID() { return "@Python_INTERPRETER_ID@"; }
+inline std::string pythonVersionString() { return "@Python_VERSION@"; }
+inline std::string pythonLibraries() { return "@Python_LIBRARIES@"; }
+inline std::string pythonStdLib() { return "@Python_STDLIB@"; }
+inline std::string pythonIncludeDirs() { return "@Python_INCLUDE_DIRS@"; }
+inline std::string numpyIncludeDir() { return "@Python_NumPy_INCLUDE_DIRS@"; }
+inline std::string numpyVersionString() { return "@Python_NumPy_VERSION@"; }
+inline std::string pythonSiteLib() { return "@Python_SITELIB@"; }
 }
 
 #endif
-- 
GitLab