Skip to content

Commit

Permalink
Merge pull request #79104 from alef/cmake-linux-vcpkg-fix
Browse files Browse the repository at this point in the history
Fix CMake Linux VCPKG build
  • Loading branch information
Maleclypse authored Jan 17, 2025
2 parents 3caae30 + febed3f commit acd0756
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ endif()
#SET(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -m32")
#SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -m32")

include(ListImportedTargets)

find_package(PkgConfig)
if (NOT DYNAMIC_LINKING)
if(NOT MSVC)
Expand Down Expand Up @@ -289,7 +291,8 @@ if (TILES)

message(STATUS "Searching for SDL2_TTF library --")
find_package(SDL2_ttf)
if (NOT (SDL2_TTF_FOUND OR TARGET SDL2::SDL2_ttf OR TARGET SDL2_ttf::SDL2_ttf-static))
if (NOT (SDL2_TTF_FOUND OR TARGET SDL2::SDL2_ttf OR TARGET SDL2_ttf::SDL2_ttf
OR TARGET SDL2_ttf::SDL2_ttf-static))
message(FATAL_ERROR
"This project requires SDL2_ttf to be installed to compile in graphical mode. \
Please install the SDL2_ttf development libraries, \
Expand All @@ -299,7 +302,8 @@ if (TILES)

message(STATUS "Searching for SDL2_image library --")
find_package(SDL2_image)
if (NOT (SDL2_IMAGE_FOUND OR TARGET SDL2::SDL2_image OR TARGET SDL2_image::SDL2_image-static))
if (NOT (SDL2_IMAGE_FOUND OR TARGET SDL2::SDL2_image OR TARGET SDL2_image::SDL2_image
OR TARGET SDL2_image::SDL2_image-static))
message(FATAL_ERROR
"This project requires SDL2_image to be installed to compile in graphical mode. \
Please install the SDL2_image development libraries, \
Expand Down
21 changes: 21 additions & 0 deletions CMakeModules/ListImportedTargets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# A simple debug script showing the locations of imported target.
# There is no load-bearing functionality.
function(ListImportedTargets dir)
message(DEBUG "List of imported targets in ${dir}:")
get_property(tgts DIRECTORY ${dir} PROPERTY IMPORTED_TARGETS)
foreach(tgt ${tgts})
message(DEBUG " ${tgt}")
get_property(p TARGET ${tgt} PROPERTY IMPORTED_LOCATION)
message(DEBUG " IMPORTED_LOCATION=${p}")
get_property(p TARGET ${tgt} PROPERTY IMPORTED_LIBNAME)
message(DEBUG " IMPORTED_LIBNAME=${p}")
foreach(cfg in DEBUG;RELEASE)
set(VAR "IMPORTED_LOCATION_${cfg}")
get_property(p TARGET ${tgt} PROPERTY ${VAR})
message(DEBUG " ${VAR}=${p}")
set(VAR "IMPORTED_LIBNAME_${cfg}")
get_property(p TARGET ${tgt} PROPERTY ${VAR})
message(DEBUG " ${VAR}=${p}")
endforeach()
endforeach()
endfunction()
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
},
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-linux",
"VCPKG_TARGET_TRIPLET": "x64-linux-dynamic",
"VCPKG_MANIFEST_DIR": "${sourceDir}/msvc-full-features/"
}
}
Expand Down
7 changes: 7 additions & 0 deletions doc/c++/COMPILING-CMAKE-VCPKG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ For the official way to build CataclysmDDA, see:
`cmake` >= 3.20.0<br/>
`vcpkg` from [vcpkg.io](https://vcpkg.io/en/getting-started.html)
`msgfmt` (optional) as part of Git Bash or msys2 in the default install paths.

On Linux (for `libxcrypt`):
`autoconf`
`automake`
`libtool`
`pkg-config`

# 2 Configure

## Presets
Expand Down
18 changes: 16 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ if (TILES)
if (RELEASE)
install(TARGETS cataclysm-tiles RUNTIME)
endif ()

if (TARGET ZLIB::ZLIB)
target_link_libraries(cataclysm-tiles-common PUBLIC ZLIB::ZLIB)
else()
target_link_libraries(cataclysm-tiles-common PUBLIC ${ZLIB_LIBRARIES})
endif()

endif ()

# Build curses version if requested
Expand Down Expand Up @@ -196,9 +203,9 @@ if (CURSES)
endif ()

target_include_directories(cataclysm-common PUBLIC
${CURSES_INCLUDE_DIR} ${NCURSES_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS}
${CURSES_INCLUDE_DIR} ${NCURSES_INCLUDE_DIRS}
)
target_link_libraries(cataclysm-common PUBLIC ${CURSES_LIBRARIES} ${ZLIB_LIBRARIES})
target_link_libraries(cataclysm-common PUBLIC ${CURSES_LIBRARIES})

if (CMAKE_USE_PTHREADS_INIT)
target_compile_options(cataclysm-common PUBLIC "-pthread")
Expand Down Expand Up @@ -233,8 +240,15 @@ if (CURSES)
if (RELEASE)
install(TARGETS cataclysm RUNTIME)
endif ()

if (TARGET ZLIB::ZLIB)
target_link_libraries(cataclysm-common PUBLIC ZLIB::ZLIB)
else()
target_link_libraries(cataclysm-common PUBLIC ${ZLIB_LIBRARIES})
endif()
endif ()


if (MINGW AND NOT RELEASE)
# Try to Install shared libraries for dev builds
# Note: It is specific to MSYS2 and uses hardcoded versions so
Expand Down

0 comments on commit acd0756

Please sign in to comment.