diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0b0c96c4..8579e6c0 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -9,40 +9,35 @@ file( COPY ncepbufr utils DESTINATION . ) # Library installation directory set(_PYVER "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}") -set(_install_dir "${CMAKE_INSTALL_FULL_LIBDIR}/python${_PYVER}/site-packages") +set(_build_dir "${CMAKE_CURRENT_BINARY_DIR}/site-packages") # Build the extension module for use in install tree -install(CODE "message(\"Building Python extension modules: -${Python3_EXECUTABLE} setup.py build\") - execute_process(COMMAND ${Python3_EXECUTABLE} setup.py build - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})") +add_custom_target(python_mod ALL) +add_dependencies(python_mod bufr_4) -# Call distutils for installation -install(CODE "if( NOT \$ENV{DESTDIR} STREQUAL \"\" ) - set( __root \"--root=\$ENV{DESTDIR}\" ) - endif() - message(\"Installing Python modules: -${Python3_EXECUTABLE} setup.py install \${__root} - --install-lib=${_install_dir} - --prefix=${CMAKE_INSTALL_PREFIX} - --record=${CMAKE_BINARY_DIR}/extra_install.txt\") - execute_process(COMMAND ${Python3_EXECUTABLE} setup.py install - \${__root} - --prefix=${CMAKE_INSTALL_PREFIX} - --install-lib=${_install_dir} - --record=${CMAKE_BINARY_DIR}/extra_install.txt - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})") +if( NOT \$ENV{DESTDIR} STREQUAL \"\" ) + set( __root \"--root=\$ENV{DESTDIR}\" ) +endif() +add_custom_command( + TARGET python_mod + COMMAND ${Python3_EXECUTABLE} setup.py install + \${__root} + --prefix=${CMAKE_INSTALL_PREFIX} + --install-lib=${_build_dir} + --record=${CMAKE_BINARY_DIR}/extra_install.txt + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS setup.py.in +) if(ENABLE_DOCS) # Uses pdoc (https://github.com/BurntSushi/pdoc) find_program(PDOC_EXECUTABLE pdoc REQUIRED) - install(CODE "message(\"Building Python API documentation: - ${PDOC_EXECUTABLE} -o ../docs/html/python' ./ncepbufr\") - set(ENV{PYTHONPATH} ${_install_dir}) - execute_process(COMMAND ${PDOC_EXECUTABLE} -o ../docs/html/python ./ncepbufr - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})") + set(ENV{PYTHONPATH} ${_build_dir}) + add_custom_command(COMMAND ${PDOC_EXECUTABLE} -o ../docs/html/python ./ncepbufr WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif() +install(DIRECTORY ${_build_dir} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/python${_PYVER}) + # Add tests add_test(NAME test_pyncepbufr_checkpoint COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/test_checkpoint.py @@ -81,5 +76,5 @@ list(APPEND _python_tests test_pyncepbufr_test) foreach(_test ${_python_tests}) set_tests_properties(${_test} - PROPERTIES ENVIRONMENT "PYTHONPATH=${_install_dir}:$ENV{PYTHONPATH}") + PROPERTIES ENVIRONMENT "PYTHONPATH=${_build_dir}:$ENV{PYTHONPATH}") endforeach()