From 67e2a7f5cbccde8926453b51960d641a92a21d86 Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Mon, 12 Feb 2024 02:36:45 +0100 Subject: [PATCH] Clean up of CMakeLists.txt and building system (#579) Replace the package assemble scripts with a cmake target --- CMakeLists.txt | 9 +++++ scripts/assemble_pip_package.bat | 61 -------------------------------- scripts/assemble_pip_package.sh | 60 ------------------------------- src/lib_python/CMakeLists.txt | 29 ++++++++------- src/vizdoom/src/CMakeLists.txt | 10 +++--- 5 files changed, 30 insertions(+), 139 deletions(-) delete mode 100755 scripts/assemble_pip_package.bat delete mode 100755 scripts/assemble_pip_package.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 220d2f9ca..b9347d402 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,14 @@ endif() if(APPLE) set(CMAKE_MACOSX_RPATH ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") + + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64") + set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE INTERNAL "" FORCE) + message(STATUS "Apple Silicon detected, building for arm64") + else() + set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE INTERNAL "" FORCE) + message(STATUS "Intel CPU detected, building for x86_64") + endif() endif(APPLE) @@ -93,6 +101,7 @@ endif() #----------------------------------------------------------------------------------------------------------------------- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(VIZDOOM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(VIZDOOM_OUTPUT_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set(VIZDOOM_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts) set(VIZDOOM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) diff --git a/scripts/assemble_pip_package.bat b/scripts/assemble_pip_package.bat deleted file mode 100755 index f39e68106..000000000 --- a/scripts/assemble_pip_package.bat +++ /dev/null @@ -1,61 +0,0 @@ -:: @echo off -setlocal enabledelayedexpansion - -set PYTHON_VERSION=%1 -set BIN_PATH=%2 -set SRC_PATH=%3 - -:: Replace back-slashes with forward-slashes -set "BIN_PATH=%BIN_PATH:/=\%" -set "SRC_PATH=%SRC_PATH:/=\%" - -set PACKAGE_DEST_DIRECTORY=%BIN_PATH%\python%PYTHON_VERSION% -set PACKAGE_DEST_PATH=%PACKAGE_DEST_DIRECTORY%\vizdoom -set PACAKGE_INIT_FILE_SRC=%SRC_PATH%\src\lib_python\__init__.py - -set VIZDOOM_EXEC_PATH=%BIN_PATH%\vizdoom.exe -set VIZDOOM_PK3_PATH=%BIN_PATH%\vizdoom.pk3 -set FREEDOOM_PATH=%SRC_PATH%\src\freedoom2.wad -set BOTS_PATH=%SRC_PATH%\src\bots.cfg -set SCENARIOS_DEST_DIR=%PACKAGE_DEST_PATH%\scenarios -set SCENARIOS_PATH=%SRC_PATH%\scenarios -set GYM_WRAPPER_DEST_DIR=%PACKAGE_DEST_PATH%\gym_wrapper -set GYM_WRAPPER_PATH=%SRC_PATH%\gym_wrapper -set GYMNASIUM_WRAPPER_DEST_DIR=%PACKAGE_DEST_PATH%\gymnasium_wrapper -set GYMNASIUM_WRAPPER_PATH=%SRC_PATH%\gymnasium_wrapper - - -if not exist "%BIN_PATH%\python%PYTHON_VERSION%\vizdoom*.pyd" ( - echo "Library for specified Python version does not exist. Aborting." - exit /B 2 -) - -if not exist "%VIZDOOM_EXEC_PATH%" ( - echo "Required ViZDoom's resources do not exist. Aborting." - exit /B 3 -) - -if not exist "%VIZDOOM_PK3_PATH%" ( - echo "Required ViZDoom's resources do not exist. Aborting." - exit /B 3 -) - -rmdir /Q /S %PACKAGE_DEST_PATH% -md %PACKAGE_DEST_PATH% - -copy "%PACAKGE_INIT_FILE_SRC%" "%PACKAGE_DEST_PATH%" -copy "%VIZDOOM_EXEC_PATH%" "%PACKAGE_DEST_PATH%" -copy "%VIZDOOM_PK3_PATH%" "%PACKAGE_DEST_PATH%" -copy "%BIN_PATH%\python%PYTHON_VERSION%\vizdoom*.pyd" "%PACKAGE_DEST_PATH%" -copy "%FREEDOOM_PATH%" "%PACKAGE_DEST_PATH%" -copy "%BOTS_PATH%" "%PACKAGE_DEST_PATH%" -copy "%BIN_PATH%\*.dll" "%PACKAGE_DEST_PATH%" - -md "%SCENARIOS_DEST_DIR% -copy "%SCENARIOS_PATH%\*.wad" "%SCENARIOS_DEST_DIR%" -copy "%SCENARIOS_PATH%\*.cfg" "%SCENARIOS_DEST_DIR%" - -md "%GYM_WRAPPER_DEST_DIR% -copy "%GYM_WRAPPER_PATH%\*.py" "%GYM_WRAPPER_DEST_DIR%" -md "%GYMNASIUM_WRAPPER_DEST_DIR% -copy "%GYMNASIUM_WRAPPER_PATH%\*.py" "%GYMNASIUM_WRAPPER_DEST_DIR%" diff --git a/scripts/assemble_pip_package.sh b/scripts/assemble_pip_package.sh deleted file mode 100755 index a7502d197..000000000 --- a/scripts/assemble_pip_package.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash - -PYTHON_VERSION=$1 -BIN_PATH=$2 -SRC_PATH=$3 - -if [ $# -ne 3 ];then - echo "Exactly three arguments required. Aborting." - exit 1 -fi - -PACKAGE_DEST_DIRECTORY="${BIN_PATH}/python${PYTHON_VERSION}" -PACKAGE_DEST_PATH="${PACKAGE_DEST_DIRECTORY}/vizdoom" -PACKAGE_INIT_FILE_SRC="${SRC_PATH}/src/lib_python/__init__.py" - -if [ "$(uname)" == "Darwin" ]; then - VIZDOOM_EXEC_PATH="${BIN_PATH}/vizdoom.app/Contents/MacOS/vizdoom" -else - VIZDOOM_EXEC_PATH="${BIN_PATH}/vizdoom" -fi - -VIZDOOM_PK3_PATH="${BIN_PATH}/vizdoom.pk3" -PYTHON_BIN_PATH="$(ls ${PACKAGE_DEST_DIRECTORY}/vizdoom*)" -FREEDOOM_PATH="${SRC_PATH}/src/freedoom2.wad" -BOTS_PATH="${SRC_PATH}/src/bots.cfg" -SCENARIOS_DEST_DIR="${PACKAGE_DEST_PATH}/scenarios" -SCENARIOS_PATH="${SRC_PATH}/scenarios" -GYM_WRAPPER_DEST_DIR="${PACKAGE_DEST_PATH}/gym_wrapper" -GYM_WRAPPER_PATH="${SRC_PATH}/gym_wrapper" -GYMNASIUM_WRAPPER_DEST_DIR="${PACKAGE_DEST_PATH}/gymnasium_wrapper" -GYMNASIUM_WRAPPER_PATH="${SRC_PATH}/gymnasium_wrapper" - -if [ ! -e ${PYTHON_BIN_PATH} ]; then - echo "Library for specified Python version does not exist. Aborting." - exit 2 -fi - -if [ ! -e ${VIZDOOM_EXEC_PATH} ] || [ ! -e ${VIZDOOM_PK3_PATH} ]; then - echo "Required ViZDoom's resources do not exist. Aborting." - exit 3 -fi - -rm -rf ${PACKAGE_DEST_PATH} -mkdir -p ${PACKAGE_DEST_PATH} - -cp ${PACKAGE_INIT_FILE_SRC} ${PACKAGE_DEST_PATH} -cp ${PYTHON_BIN_PATH} ${PACKAGE_DEST_PATH} -cp ${VIZDOOM_EXEC_PATH} ${PACKAGE_DEST_PATH} -cp ${VIZDOOM_PK3_PATH} ${PACKAGE_DEST_PATH} -cp ${FREEDOOM_PATH} ${PACKAGE_DEST_PATH} -cp ${BOTS_PATH} ${PACKAGE_DEST_PATH} - -mkdir -p ${SCENARIOS_DEST_DIR} -cp ${SCENARIOS_PATH}/*.wad ${SCENARIOS_DEST_DIR} -cp ${SCENARIOS_PATH}/*.cfg ${SCENARIOS_DEST_DIR} - -mkdir -p ${GYM_WRAPPER_DEST_DIR} -cp ${GYM_WRAPPER_PATH}/*.py ${GYM_WRAPPER_DEST_DIR} -mkdir -p ${GYMNASIUM_WRAPPER_DEST_DIR} -cp ${GYMNASIUM_WRAPPER_PATH}/*.py ${GYMNASIUM_WRAPPER_DEST_DIR} diff --git a/src/lib_python/CMakeLists.txt b/src/lib_python/CMakeLists.txt index eaa46d94d..082eca535 100644 --- a/src/lib_python/CMakeLists.txt +++ b/src/lib_python/CMakeLists.txt @@ -13,6 +13,7 @@ if(WIN32) endif() set(VIZDOOM_PYTHON_OUTPUT_DIR ${VIZDOOM_OUTPUT_DIR}/python${BUILD_PYTHON_VERSION}) +set(VIZDOOM_PYTHON_PACKAGE_DIR ${VIZDOOM_PYTHON_OUTPUT_DIR}/vizdoom) set(VIZDOOM_PYTHON_SRC_DIR ${VIZDOOM_SRC_DIR}/lib_python) set(VIZDOOM_PYTHON_INCLUDE_DIR ${VIZDOOM_INCLUDE_DIR} ${VIZDOOM_PYTHON_SRC_DIR}) @@ -70,19 +71,23 @@ set_target_properties(libvizdoom_python OUTPUT_NAME vizdoom PROJECT_LABEL "python${BUILD_PYTHON_VERSION} binding") -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}/vizdoom") -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}/vizdoom") -endif() +add_custom_target(assemble_package ALL + COMMAND ${CMAKE_COMMAND} -E make_directory ${VIZDOOM_PYTHON_PACKAGE_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $ ${VIZDOOM_PYTHON_PACKAGE_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${VIZDOOM_PYTHON_SRC_DIR}/__init__.py ${VIZDOOM_PYTHON_PACKAGE_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $ ${VIZDOOM_PYTHON_PACKAGE_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${VIZDOOM_OUTPUT_DIR}/vizdoom.pk3 ${VIZDOOM_PYTHON_PACKAGE_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${VIZDOOM_SRC_DIR}/bots.cfg ${VIZDOOM_PYTHON_PACKAGE_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${VIZDOOM_SRC_DIR}/freedoom2.wad ${VIZDOOM_PYTHON_PACKAGE_DIR} + COMMAND ${CMAKE_COMMAND} -E copy_directory ${VIZDOOM_ROOT_DIR}/scenarios ${VIZDOOM_PYTHON_PACKAGE_DIR}/scenarios + COMMAND ${CMAKE_COMMAND} -E copy_directory ${VIZDOOM_ROOT_DIR}/gym_wrapper ${VIZDOOM_PYTHON_PACKAGE_DIR}/gym_wrapper + COMMAND ${CMAKE_COMMAND} -E copy_directory ${VIZDOOM_ROOT_DIR}/gymnasium_wrapper ${VIZDOOM_PYTHON_PACKAGE_DIR}/gymnasium_wrapper + COMMENT "Assembling Python package in ${VIZDOOM_PYTHON_OUTPUT_DIR}/vizdoom" +) -set_target_properties(python_pip_package +set_target_properties(assemble_package PROPERTIES - PROJECT_LABEL "Python module") + PROJECT_LABEL "Python package") # vizdoom, vizdoom.pk3 are needed to assemble the package -add_dependencies(python_pip_package libvizdoom_python vizdoom pk3) +add_dependencies(assemble_package libvizdoom_python vizdoom pk3) diff --git a/src/vizdoom/src/CMakeLists.txt b/src/vizdoom/src/CMakeLists.txt index bb7042cb9..4603b5592 100644 --- a/src/vizdoom/src/CMakeLists.txt +++ b/src/vizdoom/src/CMakeLists.txt @@ -178,12 +178,10 @@ else( WIN32 ) add_definitions( -DNO_GTK=1 ) endif( NO_GTK ) - # Non-Windows version also needs SDL except native OS X backend - if( NOT WIN32 ) - find_package( SDL2 REQUIRED ) - include_directories( "${SDL2_INCLUDE_DIR}" ) - set( ZDOOM_LIBS ${ZDOOM_LIBS} "${SDL2_LIBRARY}" ) - endif( NOT WIN32 ) + # Non-Windows version needs SDL2 + find_package( SDL2 REQUIRED ) + include_directories( "${SDL2_INCLUDE_DIR}" ) + set( ZDOOM_LIBS ${ZDOOM_LIBS} "${SDL2_LIBRARY}" ) endif( WIN32 )