Skip to content

Commit

Permalink
Optimize building of HOG files
Browse files Browse the repository at this point in the history
Don't force building HOG files if dependency files are up-to-date.
  • Loading branch information
winterheart committed Oct 20, 2024
1 parent 74ac445 commit 4d16177
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ if(FORCE_COLORED_OUTPUT)
endif()
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

include(GNUInstallDirs)
if(FORCE_PORTABLE_INSTALL)
set(CMAKE_INSTALL_BINDIR ".")
Expand Down
51 changes: 51 additions & 0 deletions cmake/HogMaker.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Descent 3
# Copyright (C) 2024 Descent Developers
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.


# - Function making a HOG file based on supplied filelist.
#
# This module provides function MakeHog() used for building HOG files.
#
# MakeHog(
# <OUTPUT d3-full-win32.hog>
# <INPUT_FILE filelist.txt>
# [SEARCH_PATH additional_dirs]
# [DEPENDS additional_dependencies]
# )
#

function(MakeHog)
set(options)
set(oneValueArgs OUTPUT INPUT_FILE)
set(multiValueArgs SEARCH_PATH DEPENDS)

cmake_parse_arguments(PARSE_ARGV 0
"HOG"
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
)

add_custom_command(OUTPUT "${HOG_OUTPUT}"
COMMAND $<TARGET_FILE:HogMaker>
"${HOG_OUTPUT}"
"${HOG_INPUT_FILE}"
"${HOG_SEARCH_PATH}"
DEPENDS HogMaker ${HOG_INPUT_FILE} ${HOG_DEPENDS}
COMMENT "Generate ${HOG_OUTPUT}"
COMMAND_EXPAND_LISTS
)
endfunction()
16 changes: 8 additions & 8 deletions netcon/descent3onlineclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(Descent3_Online_TCP_IP PROPERTIES SUFFIX ".dylib")
endif()

include(HogMaker)
MakeHog(
OUTPUT "${PROJECT_BINARY_DIR}/Descent3/online/Descent3 Online.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/descent3onlineclient/d3online.d3c.txt"
SEARCH_PATH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Descent3_Online_TCP_IP
)
add_custom_target(Descent3_Online_TCP_IP_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Descent3 Online.d3c"
"${CMAKE_SOURCE_DIR}/netcon/descent3onlineclient/d3online.d3c.txt"
"${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
"$<TARGET_FILE_DIR:Descent3_Online_TCP_IP>"

DEPENDS Descent3_Online_TCP_IP HogMaker
COMMENT "Generate 'Descent3 Online.d3c'"
DEPENDS "${PROJECT_BINARY_DIR}/Descent3/online/Descent3 Online.d3c"
)
install(FILES "$<TARGET_FILE_DIR:Descent3>/online/Descent3 Online.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)
1 change: 0 additions & 1 deletion netcon/descent3onlineclient/d3online.d3c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ Descent3 Online.dll
Descent3 Online.dylib
d3online_main.ogf
d3online_game.ogf

16 changes: 8 additions & 8 deletions netcon/lanclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(Direct_TCP_IP PROPERTIES SUFFIX ".dylib")
endif()

include(HogMaker)
MakeHog(
OUTPUT "${PROJECT_BINARY_DIR}/Descent3/online/Direct TCP~IP.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/lanclient/TCP_IP.d3c.txt"
SEARCH_PATH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Direct_TCP_IP
)
add_custom_target(Direct_TCP_IP_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Direct TCP~IP.d3c"
"${CMAKE_SOURCE_DIR}/netcon/lanclient/TCP_IP.d3c.txt"
"${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
"$<TARGET_FILE_DIR:Direct_TCP_IP>"

DEPENDS Direct_TCP_IP HogMaker
COMMENT "Generate 'Direct TCP~IP.d3c'"
DEPENDS "${PROJECT_BINARY_DIR}/Descent3/online/Direct TCP~IP.d3c"
)
install(FILES "$<TARGET_FILE_DIR:Descent3>/online/Direct TCP~IP.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)
16 changes: 8 additions & 8 deletions netcon/mtclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(Parallax_Online PROPERTIES SUFFIX ".dylib")
endif()

include(HogMaker)
MakeHog(
OUTPUT "${PROJECT_BINARY_DIR}/Descent3/online/Parallax Online.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/mtclient/Parallax_Online.d3c.txt"
SEARCH_PATH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Parallax_Online
)
add_custom_target(Parallax_Online_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Parallax Online.d3c"
"${CMAKE_SOURCE_DIR}/netcon/mtclient/Parallax_Online.d3c.txt"
"${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
"$<TARGET_FILE_DIR:Parallax_Online>"

DEPENDS Parallax_Online HogMaker
COMMENT "Generate 'Parallax Online.d3c'"
DEPENDS "${PROJECT_BINARY_DIR}/Descent3/online/Parallax Online.d3c"
)
install(FILES "$<TARGET_FILE_DIR:Descent3>/online/Parallax Online.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)
23 changes: 10 additions & 13 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ set(SCRIPTS
SewerRat
testscript
TrainingMission
Y2K)

#add_custom_target(HogDemo-copy
# COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/scripts/data/demohog ${CMAKE_BINARY_DIR}/scripts/data/demohog/
# COMMENT "Copy script/data/demohog directory"
#)
Y2K
)

add_library(dallas STATIC DallasFuncs.cpp osiris_import.cpp osiris_vector.cpp)
set_target_properties(dallas PROPERTIES PREFIX "")
Expand Down Expand Up @@ -102,16 +98,17 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(HOG_NAME "win")
endif()

include(HogMaker)
MakeHog(
OUTPUT "${PROJECT_BINARY_DIR}/Descent3/d3-${HOG_NAME}.hog"
INPUT_FILE "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/d3-${HOG_NAME}-fullhog.txt"
SEARCH_PATH "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS ${SCRIPTS}
)
add_custom_target(HogFull
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/d3-${HOG_NAME}.hog"
"${CMAKE_SOURCE_DIR}/scripts/data/fullhog/d3-${HOG_NAME}-fullhog.txt"
"$<TARGET_FILE_DIR:AIGame>"
DEPENDS ${SCRIPTS} HogMaker data/fullhog/d3-${HOG_NAME}-fullhog.txt
COMMENT "Generate fullhog/d3-${HOG_NAME}.hog"
DEPENDS "${PROJECT_BINARY_DIR}/Descent3/d3-${HOG_NAME}.hog"
)

# Place file next to Descent3 executable on installation
install(FILES "$<TARGET_FILE_DIR:Descent3>/d3-${HOG_NAME}.hog" DESTINATION ${CMAKE_INSTALL_DATADIR})

# FIXME: there may be only one d3-linux.hog, need deal with demo somehow.
Expand Down

0 comments on commit 4d16177

Please sign in to comment.