Dawn/src/dawntools/texturetool/CMakeLists.txt

82 lines
1.7 KiB
CMake

# Copyright (c) 2021 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Texture Build Tool
project(texturetool VERSION 1.0)
add_executable(texturetool)
target_sources(texturetool
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
TextureTool.cpp
../util/Image.cpp
)
target_include_directories(texturetool
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(texturetool
PUBLIC
${DAWN_SHARED_DEFINITIONS}
DAWN_TOOL_INSTANCE=TextureTool
DAWN_TOOL_HEADER="TextureTool.hpp"
)
# Libraries
target_link_libraries(texturetool
PUBLIC
${DAWN_BUILD_HOST_LIBS}
stb
)
# Tool Function
function(tool_texture target)
# Defaults
set(FILE "" )
set(FILTER_MIN "")
set(FILTER_MAG "")
set(WRAP_X "")
set(WRAP_Y "")
set(SCALE "")
# Parse Args
foreach(_PAIR IN LISTS ARGN)
if (_PAIR MATCHES "^([^:]+)=(.*)$")
set(${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
else()
message(FATAL_ERROR "Invalid pair: ${_PAIR}")
endif()
endforeach()
# Check for missing args
if(NOT DEFINED FILE)
message(FATAL_ERROR "Missing FILE input")
endif()
set(DEPS "")
if(DAWN_BUILD_TOOLS)
set(DEPS texturetool)
endif()
add_custom_target(${target}
COMMAND texturetool
--input="${DAWN_ASSETS_SOURCE_DIR}/${FILE}"
--output="${DAWN_ASSETS_BUILD_DIR}/${target}"
--wrapX="${WRAP_X}"
--wrapY="${WRAP_Y}"
--filterMin="${FILTER_MIN}"
--filterMag="${FILTER_MIN}"
--scale="${SCALE}"
COMMENT "Generating texture ${target} from ${FILE}"
DEPENDS ${DEPS}
)
add_dependencies(${DAWN_TARGET_NAME} ${target})
endfunction()