Skip to content

Commit

Permalink
Update scripts, CMakeLists.txt and setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mwydmuch committed Sep 25, 2023
1 parent 284bab7 commit 47cfd5a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 38 deletions.
44 changes: 22 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,73 +20,73 @@ option(BUILD_ENGINE "Build ViZDoom Engine (required to build Python package)" ON

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_LINK)
if (COMMAND cmake_policy)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif (COMMAND cmake_policy)
endif()

# Add cmake_modules to module
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")

# Set the release mode if not specified
if (NOT CMAKE_BUILD_TYPE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()
endif()


# System dependent settings
#-----------------------------------------------------------------------------------------------------------------------

if (UNIX)
if(UNIX)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
endif ()
endif()

if (WIN32)
if(WIN32)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)

macro(get_WIN32_WINNT version)
if (WIN32 AND CMAKE_SYSTEM_VERSION)
if(WIN32 AND CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REPLACE "10" "A" ver ${ver})
string(REPLACE "." "" ver ${ver})
string(REGEX REPLACE "([A-F0-9])" "0\\1" ver ${ver})
string(SUBSTRING ${ver} 0 4 ver)

set(${version} "0x${ver}")
endif ()
endif()
endmacro()

get_WIN32_WINNT(ver)
add_definitions(-D_WIN32_WINNT=${ver})
endif ()
endif()

if (APPLE)
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
endif (APPLE)
endif(APPLE)


# Compiler dependent settings
#-----------------------------------------------------------------------------------------------------------------------

if (CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions("-fPIC")
# Explicitly silence some warnings
add_definitions("-Wno-implicit-fallthrough -Wno-shift-negative-value -Wno-stringop-truncation")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess -Wno-deprecated-copy") # C++ only
endif ()
endif()

if (MSVC)
if(MSVC)
string(REPLACE "/MD " "/MT " CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "/MD " "/MT " CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
string(REPLACE "/MD " "/MT " CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
string(REPLACE "/MDd " "/MTd " CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif ()
endif()


# Main library
Expand All @@ -110,9 +110,9 @@ set(VIZDOOM_LIBS
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})

if (UNIX AND NOT APPLE)
if(UNIX AND NOT APPLE)
set(VIZDOOM_LIBS ${VIZDOOM_LIBS} rt)
endif ()
endif()

configure_file(
"${VIZDOOM_LIB_SRC_DIR}/ViZDoomVersion.h.in"
Expand Down Expand Up @@ -162,14 +162,14 @@ set_target_properties(libvizdoom_shared
# ViZDoom Engine
#-----------------------------------------------------------------------------------------------------------------------

if (BUILD_ENGINE)
if(BUILD_ENGINE)
add_subdirectory(${VIZDOOM_SRC_DIR}/vizdoom)
endif ()
endif()


# Python bindings
#-----------------------------------------------------------------------------------------------------------------------

if (BUILD_PYTHON)
if(BUILD_PYTHON)
add_subdirectory(${VIZDOOM_SRC_DIR}/lib_python)
endif ()
endif()
2 changes: 1 addition & 1 deletion scripts/build_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cmake --version
gcc --version

# Report python version
python3 -c "import sys; print('Python', sys.version)"
python3 --version

# Install
python3 -m pip install .[test]
Expand Down
1 change: 0 additions & 1 deletion scripts/build_and_test_conda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ gcc --version

# Report python version
python --version
python -c "import sys; print('Python', sys.version)"

# Install
export VIZDOOM_CMAKE_ARGS="-DCMAKE_PREFIX_PATH=/root/miniconda/"
Expand Down
3 changes: 1 addition & 2 deletions scripts/install_and_test_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ ls -lha .

# Report python version
python3 --version
python3 -c "import sys; print('Python', sys.version)"

# Find matching wheel file in wheelhouse
PYTHON_VERSION=$(python3 -c "import sys; print('{}{}'.format(sys.version_info.major, sys.version_info.minor))")
PYTHON_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')")
PYTHON_WHEEL=$(ls wheelhouse/vizdoom-*-cp${PYTHON_VERSION}-cp${PYTHON_VERSION}*.whl)

# Updgrad pip and install test deps
Expand Down
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,15 @@ def run(self):
shutil.copy(mpg123_dll, build_output_path)
shutil.copy(sndfile_dll, build_output_path)
shutil.copy(openal_dll, build_output_path)

# python_standard_lib = sysconfig.get_python_lib(standard_lib=True)

python_root_dir = os.path.dirname(sys.executable)
cmake_arg_list.append(f"-DPython_ROOT_DIR={python_root_dir}")
cmake_arg_list.append("-DPython_FIND_STRATEGY=LOCATION")

if python_root_dir and os.path.exists(python_root_dir):
cmake_arg_list.append(f"-DPython_ROOT_DIR={python_root_dir}")
# Manually specified artifacts
#python_executable = sys.executable
#python_include = sysconfig.get_python_inc()
#python_standard_lib = sysconfig.get_python_lib(standard_lib=True)

if os.path.exists("CMakeCache.txt"):
os.remove("CMakeCache.txt")
Expand Down
10 changes: 5 additions & 5 deletions src/lib_python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ set(BUILD_PYTHON_VERSION "" CACHE STRING "Version of Python to build bindings fo
if("${BUILD_PYTHON_VERSION}" STREQUAL "")
# Try to find Python 3 if BUILD_PYTHON_VERSION is not set
message(STATUS "BUILD_PYTHON_VERSION is not set, trying to find Python 3, Python_ROOT_DIR is ${Python_ROOT_DIR}")
find_package(Python 3 REQUIRED)
find_package(Python 3 COMPONENTS Interpreter Development REQUIRED)
set(BUILD_PYTHON_VERSION ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR})
endif()

set (PYBIND11_PYTHON_VERSION ${BUILD_PYTHON_VERSION})
set(PYBIND11_PYTHON_VERSION ${BUILD_PYTHON_VERSION})

set(VIZDOOM_PYTHON_OUTPUT_DIR ${VIZDOOM_OUTPUT_DIR}/python${BUILD_PYTHON_VERSION})
set(VIZDOOM_PYTHON_SRC_DIR ${VIZDOOM_SRC_DIR}/lib_python)
Expand Down Expand Up @@ -67,15 +67,15 @@ set_target_properties(libvizdoom_python
OUTPUT_NAME vizdoom
PROJECT_LABEL "python${BUILD_PYTHON_VERSION} binding")

if (UNIX)
if(UNIX)
add_custom_target(python_pip_package ALL
COMMAND ${VIZDOOM_SCRIPTS_DIR}/assemble_pip_package.sh ${BUILD_PYTHON_VERSION} ${VIZDOOM_OUTPUT_DIR} ${CMAKE_SOURCE_DIR}
COMMENT "Assembling pip package in ${VIZDOOM_PYTHON_OUTPUT_DIR}/pip_package")
elseif (WIN32)
elseif(WIN32)
add_custom_target(python_pip_package ALL
COMMAND ${VIZDOOM_SCRIPTS_DIR}/assemble_pip_package.bat ${BUILD_PYTHON_VERSION} ${VIZDOOM_OUTPUT_DIR} ${CMAKE_SOURCE_DIR}
COMMENT "Assembling pip package in ${VIZDOOM_PYTHON_OUTPUT_DIR}/pip_package")
endif ()
endif()

set_target_properties(python_pip_package
PROPERTIES
Expand Down
6 changes: 3 additions & 3 deletions src/lib_python/__init__.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import sys as _sys

_COMPILED_PYTHON_VERSION = "@ViZDoom_PYTHON_VERSION_STR@"

_this_python_version = "{}.{}".format(_sys.version_info.major, _sys.version_info.minor)
_this_python_version = f"{_sys.version_info.major}.{_sys.version_info.minor}"

if _COMPILED_PYTHON_VERSION != _this_python_version:
raise SystemError(
"This interpreter version: '{}' doesn't match with version of the interpreter ViZDoom was compiled with: {}".format(
_this_python_version, _COMPILED_PYTHON_VERSION))
f"This interpreter version: '{_this_python_version}' doesn't match with version of the interpreter ViZDoom was compiled with: '{_COMPILED_PYTHON_VERSION}'"
)

from .vizdoom import __version__ as __version__
from .vizdoom import *
Expand Down
1 change: 1 addition & 0 deletions tests/build_test_cibuildwheel_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DOCKERFILES_TO_BUILD_AND_RUN=(
)

# Build wheels using cibuildwheel
#export CIBW_BUILD_VERBOSITY=3 # Uncomment to see full build logs
cibuildwheel --platform linux --arch $(uname -m)

function create_dockerfile ( ) {
Expand Down

0 comments on commit 47cfd5a

Please sign in to comment.