Changes in Python build:

- Use python/install.py to copy from source tree to build tree
- List Cxx source files in CMakeLists_files.cmake
This commit is contained in:
Joakim Hove
2019-10-28 21:33:11 +01:00
parent 99e32edd78
commit 9d1b7a83d9
3 changed files with 36 additions and 34 deletions

View File

@@ -240,27 +240,14 @@ if (OPM_ENABLE_PYTHON)
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python
OUTPUT_VARIABLE python_lib_target)
add_custom_target(copy_python ALL
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/python/install.py ${CMAKE_SOURCE_DIR}/python ${CMAKE_BINARY_DIR} 0)
add_custom_command(OUTPUT python/python/opm/${python_lib_target}
DEPENDS
python/cxx/unit_system.cpp
python/cxx/connection.cpp
python/cxx/converters.hpp
python/cxx/deck.cpp
python/cxx/deck_keyword.cpp
python/cxx/eclipse_3d_properties.cpp
python/cxx/eclipse_config.cpp
python/cxx/eclipse_grid.cpp
python/cxx/eclipse_state.cpp
python/cxx/group.cpp
python/cxx/log.cpp
python/cxx/parsecontext.cpp
python/cxx/parser.cpp
python/cxx/schedule.cpp
python/cxx/export.cpp
python/cxx/export.hpp
python/cxx/table_manager.cpp
python/cxx/well.cpp
DEPENDS ${PYTHON_CXX_DEPENDS}
DEPENDS copy_python
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/python/ ${CMAKE_BINARY_DIR}/python
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/python/setup.py
build
build_ext
@@ -284,7 +271,7 @@ if (OPM_ENABLE_PYTHON)
# setup.py install manually - optionally with the generated script
# setup-install.sh - and completely bypass cmake in the installation phase.
if (OPM_INSTALL_PYTHON)
install( CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/python/install.py ${CMAKE_BINARY_DIR}/python/python/opm ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX})")
install( CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/python/install.py ${CMAKE_BINARY_DIR}/python/python/opm ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX} 1)")
endif()
add_test(NAME python_tests

View File

@@ -171,10 +171,12 @@ if(ENABLE_ECL_INPUT)
src/opm/parser/eclipse/Utility/Stringview.cpp
)
if (OPM_ENABLE_EMBEDDED_PYTHON)
list( APPEND PYTHON_SOURCE_FILES
src/opm/parser/eclipse/Python/PythonInterp.cpp
python/cxx/unit_system.cpp
# This list is only used to register a CMake dependency between the the python
# extension and the corresponding C++ wrapper files. The cpp files actually
# listed here are repeated in the actual definition of the extension in the
# setup.py file.
list( APPEND PYTHON_CXX_SOURCE_FILES
python/cxx/connection.cpp
python/cxx/deck.cpp
python/cxx/deck_keyword.cpp
@@ -182,20 +184,26 @@ if(ENABLE_ECL_INPUT)
python/cxx/eclipse_config.cpp
python/cxx/eclipse_grid.cpp
python/cxx/eclipse_state.cpp
python/cxx/export.cpp
python/cxx/group.cpp
python/cxx/log.cpp
python/cxx/parsecontext.cpp
python/cxx/parser.cpp
python/cxx/schedule.cpp
python/cxx/export.cpp
python/cxx/table_manager.cpp
python/cxx/unit_system.cpp
python/cxx/well.cpp
python/cxx/log.cpp
)
set_source_files_properties(${PYTHON_SOURCE_FILES} PROPERTIES COMPILE_FLAGS -Wno-shadow)
list( APPEND MAIN_SOURCE_FILES ${PYTHON_SOURCE_FILES})
if (OPM_ENABLE_EMBEDDED_PYTHON)
set_source_files_properties(${PYTHON_CXX_SOURCE_FILES} PROPERTIES COMPILE_FLAGS -Wno-shadow)
set_source_files_properties(src/opm/parser/eclipse/Python/PythonInterp.cpp PROPERTIES COMPILE_FLAGS -Wno-shadow)
list( APPEND MAIN_SOURCE_FILES src/opm/parser/eclipse/Python/PythonInterp.cpp ${PYTHON_CXX_SOURCE_FILES})
endif()
list( APPEND PYTHON_CXX_DEPENDS ${PYTHON_CXX_SOURCE_FILES}
python/cxx/converters.hpp
python/cxx/export.hpp)
if(NOT cjson_FOUND)
list(APPEND MAIN_SOURCE_FILES external/cjson/cJSON.c)

View File

@@ -5,16 +5,17 @@ import compileall
src_root = sys.argv[1]
target_prefix = sys.argv[2]
install = int(sys.argv[3])
if not os.path.isdir(src_root):
sys.exit("No such directory: {}".format(src_root))
path_offset = len(os.path.dirname(src_root))
for path,_ ,fnames in os.walk(src_root):
target_path = os.path.join(target_prefix, path[path_offset+1:])
if not os.path.isdir(target_path):
print("-- Installing: {}".format(target_path))
os.makedirs(target_path)
for f in fnames:
@@ -22,10 +23,16 @@ for path,_ ,fnames in os.walk(src_root):
if ext == ".pyc":
continue
if ext == ".in":
continue
src_file = os.path.join(path, f)
target_file = os.path.join(target_path, f)
shutil.copy(src_file, target_file)
print("-- Installing: {}".format(target_file))
target_root = os.path.join(target_prefix, os.path.basename(src_root))
compileall.compile_dir(target_root)
if install:
print("-- Installing: {}".format(target_file))
if install:
target_root = os.path.join(target_prefix, os.path.basename(src_root))
compileall.compile_dir(target_root)