diff --git a/CMakeLists.txt b/CMakeLists.txt index d315c3ffed39def3daac105def26eaa06e8a3415..22217ba30b0c3771a4fd51505549b658de616778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,7 @@ if(BORNAGAIN_GUI) string(APPEND CMAKE_CXX_FLAGS " -DHAVE_QT=ON") endif() include(BornAgain/Config) +include(BornAgain/PythonAPI) include(BornAgain/PythonDocs) # debug optimization diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 69582496875801ee54173116087e5e9bbd821170..7e35d33877529a4a352962fd02833c3c8594ed06 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -17,7 +17,6 @@ if(${Cerf_IS_CPP}) string(APPEND CMAKE_CXX_FLAGS " -DCERF_AS_CPP=ON") endif() - if(BORNAGAIN_PYTHON) if(CONFIGURE_BINDINGS) @@ -99,34 +98,9 @@ set(${lib}_LIBRARY ${lib} PARENT_SCOPE) if(BORNAGAIN_PYTHON) - if(CONFIGURE_BINDINGS) - add_custom_command( - OUTPUT ${AUTO_DIR}/swig_runtime.h - COMMAND ${SWIG_EXECUTABLE} -c++;-python;-external-runtime;${AUTO_DIR}/swig_runtime.h - DEPENDS ${swig_dependencies} ${include_files} - ) - endif() - add_custom_target(${lib}_runtime DEPENDS ${AUTO_DIR}/swig_runtime.h) - add_dependencies(${lib} ${lib}_runtime) - - configure_file(${WRAP_DIR}/python/plot_utils.py - ${CMAKE_BINARY_DIR}/lib/bornagain/plot_utils.py COPYONLY) - - if(WIN32) - set(BA_MODULES_IMPORT_PATH "../../bin") - else() - set(BA_MODULES_IMPORT_PATH "..") - endif() - if(BORNAGAIN_APPLE_BUNDLE) - set(BA_MODULES_IMPORT_PATH - lib/BornAgain-${BornAgain_VERSION_MAJOR}.${BornAgain_VERSION_MINOR}) - endif() - configure_file("${WRAP_DIR}/python/__init__.py.in" - "${CMAKE_BINARY_DIR}/lib/bornagain/__init__.py" @ONLY) + add_dependencies(${lib} swig_runtime) endif() - - # --- external dependencies --- target_link_libraries(${lib} ${BornAgainFit_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) @@ -180,19 +154,6 @@ foreach(file ${include_files}) install(FILES ${file} DESTINATION ${destination_include}/${name}/${dir}) endforeach() -install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ - DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.py" ) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ - DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "README") -install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ - DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.gz") -install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ - DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.png") -install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/cpp - DESTINATION ${destination_examples} COMPONENT Examples) -install(FILES "${AUTO_DIR}/swig_runtime.h" - DESTINATION ${destination_include}/Wrap COMPONENT Headers) - if(WIN32) # python in windows required .pyd extension for the library name if(BORNAGAIN_PYTHON) diff --git a/cmake/BornAgain/PythonAPI.cmake b/cmake/BornAgain/PythonAPI.cmake index a60a2390af7f480483dcf2e7b7335b5744196fb8..59f2d020f55ea793e7fd4532113215e6dc96bafe 100644 --- a/cmake/BornAgain/PythonAPI.cmake +++ b/cmake/BornAgain/PythonAPI.cmake @@ -1,8 +1,41 @@ # Configure and install the Swig runtime, the BornAgain Python module, and more +configure_file(${WRAP_DIR}/python/plot_utils.py + ${CMAKE_BINARY_DIR}/lib/bornagain/plot_utils.py COPYONLY) +if(WIN32) + set(BA_MODULES_IMPORT_PATH "../../bin") +else() + set(BA_MODULES_IMPORT_PATH "..") +endif() +if(BORNAGAIN_APPLE_BUNDLE) + set(BA_MODULES_IMPORT_PATH + lib/BornAgain-${BornAgain_VERSION_MAJOR}.${BornAgain_VERSION_MINOR}) +endif() +configure_file("${WRAP_DIR}/python/__init__.py.in" + "${CMAKE_BINARY_DIR}/lib/bornagain/__init__.py" @ONLY) +if(CONFIGURE_BINDINGS) + add_custom_command( + OUTPUT ${AUTO_DIR}/swig_runtime.h + COMMAND ${SWIG_EXECUTABLE} -c++;-python;-external-runtime;${AUTO_DIR}/swig_runtime.h + DEPENDS ${swig_dependencies} ${include_files} + ) +endif() +add_custom_target(swig_runtime DEPENDS ${AUTO_DIR}/swig_runtime.h) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ + DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.py" ) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ + DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "README") +install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ + DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.gz") +install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ + DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.png") +install(DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/cpp + DESTINATION ${destination_examples} COMPONENT Examples) +install(FILES "${AUTO_DIR}/swig_runtime.h" + DESTINATION ${destination_include}/Wrap COMPONENT Headers) # Install bornagain/__init__.py and utilites install(DIRECTORY "${CMAKE_BINARY_DIR}/lib/bornagain/"