diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8607d1f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,60 @@ + +cmake_minimum_required (VERSION 2.8.12) +project (loot_api_python) +include(ExternalProject) + +set(EXTERNAL_PROJECTS_PATH "${CMAKE_BINARY_DIR}/external/src") +make_directory(${EXTERNAL_PROJECTS_PATH}) + +####################################### +# pybind11 +####################################### + +set(PYBIND11_URL "https://github.com/pybind/pybind11/archive/v1.8.1.tar.gz") +set(PYBIND11_DOWNLOAD_PATH "${EXTERNAL_PROJECTS_PATH}/pybind11-1.8.1.tar.gz") +set(PYBIND11_EXTRACTED_PATH "${EXTERNAL_PROJECTS_PATH}/pybind11-1.8.1") + +if (NOT EXISTS ${PYBIND11_DOWNLOAD_PATH}) + file(DOWNLOAD ${PYBIND11_URL} ${PYBIND11_DOWNLOAD_PATH}) +endif() + +execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${PYBIND11_DOWNLOAD_PATH} + WORKING_DIRECTORY ${EXTERNAL_PROJECTS_PATH} + RESULT_VARIABLE result) + +add_subdirectory(${PYBIND11_EXTRACTED_PATH}) + +####################################### +# LOOT API +####################################### + +set(LOOT_API_URL "https://bintray.com/wrinklyninja/loot/download_file?file_path=loot-api_0.9.2-20-g22d0577_api-archive-lib.7z") +set(LOOT_API_DOWNLOAD_PATH "${EXTERNAL_PROJECTS_PATH}/loot-api_0.9.2-20-g22d0577_api-archive-lib.7z") +set(LOOT_API_EXTRACTED_PATH "${EXTERNAL_PROJECTS_PATH}/loot-api_0.9.2-20-g22d0577_api-archive-lib") + +if (NOT EXISTS ${LOOT_API_DOWNLOAD_PATH}) + file(DOWNLOAD ${LOOT_API_URL} ${LOOT_API_DOWNLOAD_PATH}) +endif() + +execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xfJ ${LOOT_API_DOWNLOAD_PATH} + WORKING_DIRECTORY ${EXTERNAL_PROJECTS_PATH} + RESULT_VARIABLE result) + +include_directories("${LOOT_API_EXTRACTED_PATH}/include") +link_directories(${LOOT_API_EXTRACTED_PATH}) +set (LOOT_API_LIBRARIES "${CMAKE_STATIC_LIBRARY_PREFIX}loot_api${CMAKE_SHARED_LIBRARY_SUFFIX}") + +####################################### +# Python Module +####################################### + +pybind11_add_module(loot_api "${CMAKE_SOURCE_DIR}/src/main.cpp") + +target_link_libraries(loot_api PRIVATE ${LOOT_API_LIBRARIES}) + +FOREACH(loot_api_library ${LOOT_API_LIBRARIES}) + add_custom_command(TARGET loot_api POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${LOOT_API_EXTRACTED_PATH}/${loot_api_library} + $/${loot_api_library}) +ENDFOREACH() diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a7e10e --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +LOOT API Python Module +======================= + +A Python module that wraps the LOOT API, generated by [pybind11](https://github.com/pybind/pybind11). + +## Build Instructions + +The module's build system uses [CMake](https://cmake.org/), so make sure it's installed, then run it, and build the generated solution file. + +Only Windows support has been tested, though Linux builds should also be possible. + +## Usage + +Copy the `loot_api.pyd` file that is built and the `loot_api.dll` file in the same directory to wherever you wish to import the module from, then: + +``` +>>> import loot_api +>>> loot_api.loot_is_compatible(0,9,0) +True +``` + +**Note:** The module is currently built against revision [22d0577](https://github.com/loot/loot/tree/22d0577415ef3e8598d5e145209b14e03c4e144e) of the API, which is post-0.9.2 and pre-0.10.0, but uses the v0.10 metadata syntax (as specified at that revision, in case there are further changes before the v0.10 release). diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..4a63f96 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,34 @@ +/* LOOT + + A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and + Fallout: New Vegas. + + Copyright (C) 2012-2016 WrinklyNinja + + This file is part of LOOT. + + LOOT is free software: you can redistribute + it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + LOOT is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LOOT. If not, see + . +*/ + +#include +#include + +PYBIND11_PLUGIN(loot_api) { + pybind11::module m("loot_api", "A Python module that wraps the LOOT API, generated by pybind11."); + + m.def("loot_is_compatible", &loot_is_compatible, "Checks for API compatibility."); + + return m.ptr(); +}