Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource.dat fixxors. #759

Merged
merged 5 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ if(UNIX AND NOT APPLE)
endif(UNIX AND NOT APPLE)

include(PrecompiledHeader) #Precompiled Header helper macros
include(PythonUtils)

if(WIN32)
# libCurl isn't smart enough to detect this for us, so we have to configure it ourselves
Expand Down Expand Up @@ -210,7 +211,6 @@ if(PLASMA_PIPELINE STREQUAL "OpenGL")
endif(PLASMA_PIPELINE STREQUAL "OpenGL")

#Allow us to disable certain parts of the build
option(PLASMA_BUILD_RESOURCE_DAT "Do we want to build resource.dat?" ON)
option(PLASMA_BUILD_LAUNCHER "Do we want to build plUruLauncher?" ON)
option(PLASMA_BUILD_TOOLS "Do we want to build the Plasma tools?" ON)
option(PLASMA_BUILD_TESTS "Do we want to build the unit tests?" OFF)
Expand Down
78 changes: 61 additions & 17 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,61 @@ if(MOVIE_AVAILABLE)
include_directories(${Opus_INCLUDE_DIR})
endif()

# Test for Python Interpreter, which will be used for extra build scripts if available
if(Python3_Interpreter_FOUND)
include(FindPythonModule)
set(external_SCRIPTS
external/create_resource_dat.py
external/makeres.py
external/render_svg.py
external/scalergba.py
)

set(external_SOURCES
external/Cursor_Base.svg
external/Linking_Book.svg
external/Loading_Text_rasterfont.svg
external/Voice_Chat.svg
)

# Test for Python modules needed to build resource.dat
find_python_module(cairosvg)
find_python_module(PIL)
find_program(
PNGCRUSH_EXECUTABLE pngcrush
DOC "Path to pngcrush"
)

if((DEFINED PY_CAIROSVG) AND (DEFINED PY_PIL))
set(CAN_BUILD_RESOURCE_DAT ON)
endif((DEFINED PY_CAIROSVG) AND (DEFINED PY_PIL))
endif(Python3_Interpreter_FOUND)
# Can we generate the resource.dat file?
python_test_modules(
MODULES cairosvg PIL
REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/external/requirements.txt"
)

cmake_dependent_option(PLASMA_BUILD_RESOURCE_DAT "Do we want to build resource.dat?" ON "cairosvg_FOUND AND PIL_FOUND" OFF)
cmake_dependent_option(RESOURCE_OPTIMIZE "Optimize the images in resource.dat" ON "PLASMA_BUILD_RESOURCE_DAT AND PNGCRUSH_EXECUTABLE" OFF)
cmake_dependent_option(RESOURCE_BRUTE "Allow pngcrush brute-force optimization" OFF "PLASMA_BUILD_RESOURCE_DAT AND PNGCRUSH_EXECUTABLE" OFF)

if(PLASMA_BUILD_RESOURCE_DAT)
set(external_DAT "${CMAKE_CURRENT_BINARY_DIR}/resource.dat")
if(RESOURCE_OPTIMIZE)
string(APPEND OPTIMIZE_ARGUMENT "--pngcrush \"${PNGCRUSH_EXECUTABLE}\" ")
endif()
if(RESOURCE_BRUTE)
string(APPEND OPTIMIZE_ARGUMENT "--brute ")
endif()

add_custom_command(
OUTPUT ${external_DAT}
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/external/makeres.py"
--render --package
${OPTIMIZE_ARGUMENT}
-i "${CMAKE_CURRENT_SOURCE_DIR}/external"
-w "${CMAKE_CURRENT_BINARY_DIR}"
-o "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS ${external_SCRIPTS} ${external_SOURCES}
)

install(
FILES "${external_DAT}"
DESTINATION client
)
endif()

set(plClient_HEADERS
plClient.h
Expand Down Expand Up @@ -50,12 +93,9 @@ set(plClient_RESOURCES
)

add_executable(plClient WIN32 ${plClient_SOURCES} ${plClient_HEADERS}
${plClient_TEXT} ${plClient_RESOURCES})

if(CAN_BUILD_RESOURCE_DAT AND PLASMA_BUILD_RESOURCE_DAT)
add_subdirectory(external)
add_dependencies(plClient externalResources)
endif()
${plClient_TEXT} ${plClient_RESOURCES}
${external_SCRIPTS} ${external_SOURCES} ${external_DAT}
)

if(PLASMA_EXTERNAL_RELEASE)
set_target_properties(plClient PROPERTIES OUTPUT_NAME "UruExplorer")
Expand Down Expand Up @@ -184,7 +224,11 @@ install(
DESTINATION client
)

if(PLASMA_BUILD_RESOURCE_DAT)
source_group("Client Resource Scripts" FILES ${external_SCRIPTS})
source_group("Client Resource Images" FILES ${external_SOURCES})
endif()
source_group("Source Files" FILES ${plClient_SOURCES})
source_group("Header Files" FILES ${plClient_HEADERS})
source_group("Text" FILES ${plClient_TEXT})
source_group("Resource Files" FILES ${plClient_RESOURCES})
source_group("Windows Resource Files" FILES ${plClient_RESOURCES})
54 changes: 0 additions & 54 deletions Sources/Plasma/Apps/plClient/external/CMakeLists.txt

This file was deleted.

6 changes: 1 addition & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ install:
$path = (Get-Location).Path
Set-Location build

Write-Host "Installing Python modules... " -noNewLine
C:\Python27\python.exe -m pip install -r ../requirements.txt 2> $null
Write-Host "OK" -foregroundColor Green

Write-Host "Installing library dependencies... "
Set-Location C:\Tools\vcpkg
git pull 2> $null
Expand All @@ -49,7 +45,7 @@ before_build:

cmake -Wno-dev -DCMAKE_TOOLCHAIN_FILE=C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x86-windows-static-md `
-DCMAKE_BUILD_TYPE=$Env:CONFIGURATION -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=bin -DQt5_DIR=C:\Qt\$Env:QT_VER\msvc2017\lib\cmake\Qt5 `
-DPLASMA_EXTERNAL_RELEASE="$Env:PLASMA_EXTERNAL_RELEASE" -DPLASMA_BUILD_TESTS=ON -DPLASMA_BUILD_TOOLS=ON -DPLASMA_BUILD_RESOURCE_DAT=ON ..
-DPLASMA_EXTERNAL_RELEASE="$Env:PLASMA_EXTERNAL_RELEASE" -DPLASMA_BUILD_TESTS=ON -DPLASMA_BUILD_TOOLS=ON -DENABLE_PIP_INSTALL=ON ..
build:
project: build/Plasma.sln
parallel: true
Expand Down
29 changes: 0 additions & 29 deletions cmake/FindPythonModule.cmake

This file was deleted.

67 changes: 67 additions & 0 deletions cmake/PythonUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# TODO: Eventually, we want to automatically turn on this auto-pip install functionality. That
# should only be done when we KNOW that we are in an isolated configuration of Python.
option(ENABLE_PIP_INSTALL "Allow automatic installation of Python dependency modules." OFF)

function(python_test_modules)
cmake_parse_arguments(_ptm "DONT_INSTALL;REQUIRED" "REQUIREMENTS_FILE" "MODULES" ${ARGN})

if(NOT _ptm_MODULES)
message(FATAL_ERROR "python_test_modules() must be given a list of MODULES")
endif()

# Optional: attempt to install modules from pip before checking their existence.
if(ENABLE_PIP_INSTALL AND NOT _ptm_DONT_INSTALL)
if(NOT _PLASMA_ENSUREPIP_DONE)
message(STATUS "Bootstrapping pip...")
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m ensurepip
RESULT_VARIABLE RETURNCODE
OUTPUT_QUIET ERROR_QUIET
)
if(RETURNCODE)
message(WARNING "Unable to bootstrap pip")
endif()
set(_PLASMA_ENSUREPIP_DONE TRUE CACHE INTERNAL "" FORCE)
endif()

if(_ptm_REQUIREMENTS_FILE)
message(STATUS "Installing Python modules from: ${_ptm_REQUIREMENTS_FILE}")
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m pip install -r "${_ptm_REQUIREMENTS_FILE}"
RESULT_VARIABLE RETURNCODE
OUTPUT_QUIET ERROR_QUIET
)
else()
message(STATUS "Installing Python modules: ${_ptm_MODULES}")
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m pip install ${_ptm_MODULES}
OUTPUT_QUIET ERROR_QUIET
)
endif()

if(RETURNCODE)
message(WARNING "Failed to install modules")
endif()
endif()

foreach(_module_NAME IN LISTS _ptm_MODULES)
if(Python3_EXECUTABLE)
execute_process(
COMMAND "${Python3_EXECUTABLE}" -c "import ${_module_NAME}"
RESULT_VARIABLE RETURNCODE
OUTPUT_QUIET ERROR_QUIET
)
if(NOT RETURNCODE)
set(${_module_NAME}_FOUND TRUE PARENT_SCOPE)
else()
set(${_module_NAME}_FOUND FALSE PARENT_SCOPE)
endif()
else()
set(${_module_NAME}_FOUND FALSE PARENT_SCOPE)
endif()

if(_ptm_REQUIRED AND NOT ${_module_NAME}_FOUND)
message(FATAL_ERROR "Could NOT find Python3 Module: ${_module_NAME}")
endif()
endforeach()
endfunction()