From 9e498536b6af7770570db41ab59ec505b59e1c30 Mon Sep 17 00:00:00 2001 From: Andrew Dutcher Date: Thu, 15 Sep 2016 00:28:19 -0700 Subject: [PATCH] Fix cmake build to work with the new system --- contrib/cmake/examples/CMakeLists.txt | 1 + contrib/cmake/examples/python/CMakeLists.txt | 24 ++++++++++ contrib/cmake/src/api/python/CMakeLists.txt | 49 +++++++++++++------- 3 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 contrib/cmake/examples/python/CMakeLists.txt diff --git a/contrib/cmake/examples/CMakeLists.txt b/contrib/cmake/examples/CMakeLists.txt index 49ea72fdc..e596ed3dd 100644 --- a/contrib/cmake/examples/CMakeLists.txt +++ b/contrib/cmake/examples/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(c) add_subdirectory(c++) add_subdirectory(tptp) +add_subdirectory(python) diff --git a/contrib/cmake/examples/python/CMakeLists.txt b/contrib/cmake/examples/python/CMakeLists.txt new file mode 100644 index 000000000..fdbb7891f --- /dev/null +++ b/contrib/cmake/examples/python/CMakeLists.txt @@ -0,0 +1,24 @@ +set(python_example_files + example.py + visitor.py +) + +set(z3py_bindings_build_dest "${CMAKE_BINARY_DIR}/python") + +set(build_z3_python_examples_target_depends "") +foreach (example_file ${python_example_files}) + add_custom_command(OUTPUT "${z3py_bindings_build_dest}/${example_file}" + COMMAND "${CMAKE_COMMAND}" "-E" "copy" + "${CMAKE_CURRENT_SOURCE_DIR}/${example_file}" + "${z3py_bindings_build_dest}/${example_file}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${example_file}" + COMMENT "Copying \"${example_file}\" to ${z3py_bindings_build_dest}/${example_file}" + ) + list(APPEND build_z3_python_examples_target_depends "${z3py_bindings_build_dest}/${example_file}") +endforeach() + +add_custom_target(build_z3_python_examples + ALL + DEPENDS + ${build_z3_python_examples_target_depends} +) diff --git a/contrib/cmake/src/api/python/CMakeLists.txt b/contrib/cmake/src/api/python/CMakeLists.txt index 6babb2069..375890c91 100644 --- a/contrib/cmake/src/api/python/CMakeLists.txt +++ b/contrib/cmake/src/api/python/CMakeLists.txt @@ -4,31 +4,34 @@ message(STATUS "Emitting rules to build Z3 python bindings") ############################################################################### # This allows the python bindings to be used directly from the build directory set(z3py_files - z3.py - z3num.py - z3poly.py - z3printer.py - z3rcf.py - z3types.py - z3util.py + z3/__init__.py + z3/z3.py + z3/z3num.py + z3/z3poly.py + z3/z3printer.py + z3/z3rcf.py + z3/z3types.py + z3/z3util.py ) -set(z3py_bindings_build_dest "${CMAKE_BINARY_DIR}") +set(z3py_bindings_build_dest "${CMAKE_BINARY_DIR}/python") +file(MAKE_DIRECTORY "${z3py_bindings_build_dest}") +file(MAKE_DIRECTORY "${z3py_bindings_build_dest}/z3") set(build_z3_python_bindings_target_depends "") foreach (z3py_file ${z3py_files}) - add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3/${z3py_file}" + add_custom_command(OUTPUT "${z3py_bindings_build_dest}/${z3py_file}" COMMAND "${CMAKE_COMMAND}" "-E" "copy" - "${CMAKE_CURRENT_SOURCE_DIR}/z3/${z3py_file}" - "${z3py_bindings_build_dest}/z3.py" - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/z3/${z3py_file}" - COMMENT "Copying \"${z3py_file}\" to ${z3py_bindings_build_dest}/z3.py/${z3py_file}" + "${CMAKE_CURRENT_SOURCE_DIR}/${z3py_file}" + "${z3py_bindings_build_dest}/${z3py_file}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${z3py_file}" + COMMENT "Copying \"${z3py_file}\" to ${z3py_bindings_build_dest}/${z3py_file}" ) list(APPEND build_z3_python_bindings_target_depends "${z3py_bindings_build_dest}/${z3py_file}") endforeach() # Generate z3core.py -add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3core.py" +add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3/z3core.py" COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/scripts/update_api.py" ${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN} @@ -43,10 +46,10 @@ add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3core.py" COMMENT "Generating z3core.py" ${ADD_CUSTOM_COMMAND_USES_TERMINAL_ARG} ) -list(APPEND build_z3_python_bindings_target_depends "${z3py_bindings_build_dest}/z3core.py") +list(APPEND build_z3_python_bindings_target_depends "${z3py_bindings_build_dest}/z3/z3core.py") # Generate z3consts.py -add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3consts.py" +add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3/z3consts.py" COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/scripts/mk_consts_files.py" ${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN} @@ -59,13 +62,23 @@ add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3consts.py" COMMENT "Generating z3consts.py" ${ADD_CUSTOM_COMMAND_USES_TERMINAL_ARG} ) -list(APPEND build_z3_python_bindings_target_depends "${z3py_bindings_build_dest}/z3consts.py") +list(APPEND build_z3_python_bindings_target_depends "${z3py_bindings_build_dest}/z3/z3consts.py") + +# Link libz3 into the python directory so bindings work out of the box +add_custom_command(OUTPUT "${z3py_bindings_build_dest}/libz3${CMAKE_SHARED_MODULE_SUFFIX}" + COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" + "${CMAKE_BINARY_DIR}/libz3${CMAKE_SHARED_MODULE_SUFFIX}" + "${z3py_bindings_build_dest}/libz3${CMAKE_SHARED_MODULE_SUFFIX}" + DEPENDS libz3 + COMMENT "Linking libz3 into python directory" +) # Convenient top-level target add_custom_target(build_z3_python_bindings ALL DEPENDS ${build_z3_python_bindings_target_depends} + "${z3py_bindings_build_dest}/libz3${CMAKE_SHARED_MODULE_SUFFIX}" ) ############################################################################### @@ -116,7 +129,7 @@ if (INSTALL_PYTHON_BINDINGS) # Using DESTDIR still seems to work even if we use an absolute path message(STATUS "Python bindings will be installed to \"${CMAKE_INSTALL_PYTHON_PKG_DIR}\"") install(FILES ${build_z3_python_bindings_target_depends} - DESTINATION "${CMAKE_INSTALL_PYTHON_PKG_DIR}" + DESTINATION "${CMAKE_INSTALL_PYTHON_PKG_DIR}/z3" ) else() message(STATUS "Not emitting rules to install Z3 python bindings")