Skip to content

Commit

Permalink
Move all built targets into "${CMAKE_BINARY_DIR}/build" directory
Browse files Browse the repository at this point in the history
This solves problem of inability determine generated output directory of libraries targets. Now `add_custom_command()`, used on HOG generation, correctly locates all needed paths and not depends on generated variables.
  • Loading branch information
winterheart committed Oct 26, 2024
1 parent cc7fbd4 commit 6d9ef64
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
9 changes: 6 additions & 3 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ The build process uses [**CMake**](https://cmake.org/) and, by default, [**Ninja
```
See [Build Options](#build-options) below for more information on `Debug` vs `Release`.
Once CMake finishes, the built files will be put in `builds\win\Descent3\Debug` or `builds\win\Descent3\Release`.
Once CMake finishes, the built files will be put in `builds\win\Descent3\build\Debug` or
`builds\win\Descent3\build\Release`.
## Building - macOS
1. **Install the prerequisite build tools.**
Expand Down Expand Up @@ -87,7 +88,8 @@ Once CMake finishes, the built files will be put in `builds\win\Descent3\Debug`
```
See [Build Options](#build-options) below for more information on `Debug` vs `Release`.
Once CMake finishes, the built files will be put in `builds/mac/Descent3/Debug` or `builds/mac/Descent3/Release`.
Once CMake finishes, the built files will be put in `builds/mac/Descent3/build/Debug` or
`builds/mac/Descent3/build/Release`.
## Building - Linux
1. **Install the prerequisite build tools.**
Expand Down Expand Up @@ -147,7 +149,8 @@ Once CMake finishes, the built files will be put in `builds/mac/Descent3/Debug`
```
See [Build Options](#build-options) below for more information on `Debug` vs `Release`.
Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`.
Once CMake finishes, the built files will be put in `builds/linux/Descent3/build/Debug` or
`builds/linux/Descent3/build/Release`.
## Cross-compilation
Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ if(FORCE_PORTABLE_INSTALL)
set(CMAKE_INSTALL_DOCDIR ".")
endif()

# All built targets will placed here
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build")

# Get info about multi-config environment
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# Properly determine output directory for generated files
if(IS_MULTI_CONFIG)
set(D3_GENERATED_FILES_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build/$<CONFIG>")
else ()
set(D3_GENERATED_FILES_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build")
endif()

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/installed" CACHE PATH "Default install path" FORCE)
endif()
Expand Down
11 changes: 0 additions & 11 deletions Descent3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,6 @@ add_dependencies(Descent3
tanarchy
)

# Custom command for copying custom targets such HOG files
# We cannot use here TARGET_FILE_DIR generated expressions since custom target don't have one
add_custom_command(TARGET Descent3 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/scripts/$<CONFIG>/d3-${HOG_NAME}.hog" "$<TARGET_FILE_DIR:Descent3>"
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:Descent3>/online"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/netcon/descent3onlineclient/$<CONFIG>/Descent3 Online.d3c" "$<TARGET_FILE_DIR:Descent3>/online"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/netcon/lanclient/$<CONFIG>/Direct TCP~IP.d3c" "$<TARGET_FILE_DIR:Descent3>/online"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/netcon/mtclient/$<CONFIG>/Parallax Online.d3c" "$<TARGET_FILE_DIR:Descent3>/online"
COMMENT "Copying HOG-files into Descent3 work dir"
)

install(TARGETS Descent3 RUNTIME BUNDLE DESTINATION .)
if(MSVC)
install(FILES $<TARGET_PDB_FILE:Descent3> DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down
8 changes: 6 additions & 2 deletions netcon/descent3onlineclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ endif()
include(HogMaker)
MakeHog(
TARGET Descent3_Online_TCP_IP_Hog
OUTPUT "$<CONFIG>/Descent3 Online.d3c"
OUTPUT "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Descent3 Online.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/descent3onlineclient/d3online.d3c.txt"
SEARCH_PATH "$<TARGET_FILE_DIR:Descent3_Online_TCP_IP>" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Descent3_Online_TCP_IP
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Descent3 Online.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)

install(
FILES "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Descent3 Online.d3c"
DESTINATION ${CMAKE_INSTALL_DATADIR}/online
)
8 changes: 6 additions & 2 deletions netcon/lanclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ endif()
include(HogMaker)
MakeHog(
TARGET Direct_TCP_IP_Hog
OUTPUT "$<CONFIG>/Direct TCP~IP.d3c"
OUTPUT "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Direct TCP~IP.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/lanclient/TCP_IP.d3c.txt"
SEARCH_PATH "$<TARGET_FILE_DIR:Direct_TCP_IP>" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Direct_TCP_IP
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Direct TCP~IP.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)

install(
FILES "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Direct TCP~IP.d3c"
DESTINATION ${CMAKE_INSTALL_DATADIR}/online
)
7 changes: 5 additions & 2 deletions netcon/mtclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ endif()
include(HogMaker)
MakeHog(
TARGET Parallax_Online_Hog
OUTPUT "$<CONFIG>/Parallax Online.d3c"
OUTPUT "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Parallax Online.d3c"
INPUT_FILE "${CMAKE_SOURCE_DIR}/netcon/mtclient/Parallax_Online.d3c.txt"
SEARCH_PATH "$<TARGET_FILE_DIR:Parallax_Online>" "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
DEPENDS Parallax_Online
)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Parallax Online.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)
install(
FILES "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/online/Parallax Online.d3c"
DESTINATION ${CMAKE_INSTALL_DATADIR}/online
)
8 changes: 6 additions & 2 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ endforeach()
include(HogMaker)
MakeHog(
TARGET HogFull
OUTPUT "$<CONFIG>/d3-${HOG_NAME}.hog"
OUTPUT "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/d3-${HOG_NAME}.hog"
INPUT_FILE "${CMAKE_SOURCE_DIR}/scripts/data/fullhog/d3-${HOG_NAME}-fullhog.txt"
SEARCH_PATH "$<TARGET_FILE_DIR:AIGame>"
DEPENDS ${SCRIPTS}
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/d3-${HOG_NAME}.hog" DESTINATION ${CMAKE_INSTALL_DATADIR})

install(
FILES "${D3_GENERATED_FILES_OUTPUT_DIRECTORY}/d3-${HOG_NAME}.hog"
DESTINATION ${CMAKE_INSTALL_DATADIR}
)

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

0 comments on commit 6d9ef64

Please sign in to comment.