Skip to content

Commit

Permalink
Merge pull request #61225 from alef/cmake-presets-part1
Browse files Browse the repository at this point in the history
Build Windows Release with CMake (part1)
  • Loading branch information
kevingranade authored Oct 20, 2022
2 parents 842769c + a27e10d commit 3c575e5
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 54 deletions.
60 changes: 39 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.21)

project(CataclysmDDA)

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
list(APPEND CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/CMakeModules)
if (NOT VCPKG_MANIFEST_MODE)
list(APPEND CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/CMakeModules/Find)
endif()

set(CMAKE_TLS_VERIFY ON)

Expand Down Expand Up @@ -126,10 +129,10 @@ endif ()

if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Windows|MSYS)")
if (NOT DATA_PREFIX)
set(DATA_PREFIX ${CMAKE_INSTALL_PREFIX})
set(DATA_PREFIX ${CMAKE_INSTALL_PREFIX}/data)
endif ()
if (NOT LOCALE_DIR)
set(LOCALE_DIR ${CMAKE_INSTALL_PREFIX})
set(LOCALE_DIR ${CMAKE_INSTALL_PREFIX}/lang)
endif ()
if (NOT BIN_PREFIX)
set(BIN_PREFIX ${CMAKE_INSTALL_PREFIX})
Expand Down Expand Up @@ -265,7 +268,7 @@ if (TILES)
# Find SDL, SDL_ttf & SDL_image for graphical install
message(STATUS "Searching for SDL2 library --")
find_package(SDL2)
if (NOT SDL2_FOUND)
if (NOT (SDL2_FOUND OR TARGET SDL2::SDL2))
message(FATAL_ERROR
"This project requires SDL2 to be installed to compile in graphical mode. \
Please install the SDL2 development libraries, \
Expand All @@ -285,7 +288,7 @@ if (TILES)

message(STATUS "Searching for SDL2_TTF library --")
find_package(SDL2_ttf)
if (NOT SDL2_TTF_FOUND)
if (NOT (SDL2_TTF_FOUND 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 @@ -294,8 +297,12 @@ if (TILES)
endif ()

message(STATUS "Searching for SDL2_image library --")
find_package(SDL2_image)
if (NOT SDL2_IMAGE_FOUND)
if(VCPKG_MANIFEST_MODE)
find_package(sdl2-image)
else()
find_package(SDL2_image)
endif()
if (NOT (SDL2_IMAGE_FOUND OR TARGET SDL2::SDL2_image))
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 Expand Up @@ -335,12 +342,21 @@ if (SOUND)
# Sound requires SDL_mixer library
message(STATUS "Searching for SDL2_mixer library --")
find_package(SDL2_mixer)
if (NOT SDL2_MIXER_FOUND)
message(FATAL_ERROR
"You need the SDL2_mixer development library \
to be able to compile with sound enabled. \
See doc/COMPILING/COMPILING-CMAKE.md for details and more info.")
endif ()
if(VCPKG_MANIFEST_MODE)
if (NOT TARGET SDL2_mixer::SDL2_mixer-static) # TODO x64-mingw-static
message(FATAL_ERROR
"You need the SDL2_mixer development library \
to be able to compile with sound enabled. \
See doc/COMPILING/COMPILING-CMAKE.md for details and more info.")
endif()
else()
if (NOT SDL2_MIXER_FOUND)
message(FATAL_ERROR
"You need the SDL2_mixer development library \
to be able to compile with sound enabled. \
See doc/COMPILING/COMPILING-CMAKE.md for details and more info.")
endif ()
endif()
endif ()

if (BACKTRACE)
Expand All @@ -360,6 +376,14 @@ if (USE_HOME_DIR)
add_definitions(-DUSE_HOME_DIR)
endif ()

find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND AND CATA_CCACHE)
set(CMAKE_C_COMPILER_LAUNCHER ccache)
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
set(CMAKE_C_LINKER_LAUNCHER ccache)
set(CMAKE_CXX_LINKER_LAUNCHER ccache)
endif ()

add_subdirectory(src)
add_subdirectory(data)
if (NOT MSVC)
Expand All @@ -382,9 +406,3 @@ add_custom_target(uninstall
"${CMAKE_COMMAND}"
-P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND AND CATA_CCACHE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif ()

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 10 additions & 8 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ if (SOUND)
${CMAKE_SOURCE_DIR}/data/sound)
endif ()

if (TILES)
set(CATACLYSM_DATA_DIRS
${CATACLYSM_DATA_DIRS}
${CMAKE_SOURCE_DIR}/gfx)
endif ()

set(CATACLYSM_DATA_FILES
${CMAKE_SOURCE_DIR}/data/changelog.txt
${CMAKE_SOURCE_DIR}/data/cataicon.ico
${CMAKE_SOURCE_DIR}/data/fontdata.json
${CMAKE_SOURCE_DIR}/LICENSE.txt)
${CMAKE_SOURCE_DIR}/data/fontdata.json)

if (RELEASE)
install(DIRECTORY ${CATACLYSM_DATA_DIRS} DESTINATION ${DATA_PREFIX})
install(FILES ${CATACLYSM_DATA_FILES} DESTINATION ${DATA_PREFIX})
install(FILES
${CMAKE_SOURCE_DIR}/README.md
${CMAKE_SOURCE_DIR}/LICENSE.txt
${CMAKE_SOURCE_DIR}/LICENSE-OFL-Terminus-Font.txt
DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/doc DESTINATION ${CMAKE_INSTALL_PREFIX})
if (TILES)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/gfx DESTINATION ${CMAKE_INSTALL_PREFIX})
endif()
endif ()
17 changes: 10 additions & 7 deletions lang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ else ()
DEPENDS translations_prepare)
endif ()

set(DIRS "${LANGUAGES}")
list(TRANSFORM DIRS REPLACE "\(.+\)" lang/mo/\\1/LC_MESSAGES)
add_custom_command(
TARGET translations_prepare
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
make_directory ${DIRS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

foreach (LANG ${LANGUAGES})
add_custom_command(
TARGET translations_prepare
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
make_directory ${CMAKE_SOURCE_DIR}/lang/mo/${LANG}/LC_MESSAGES
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_command(
TARGET translations_compile
PRE_BUILD
Expand All @@ -92,7 +95,7 @@ foreach (LANG ${LANGUAGES})
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
if (RELEASE)
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
#install(DIRECTORY ${CMAKE_SOURCE_DIR}/lang/mo/${LANG} DESTINATION ${DATA_PREFIX})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/lang/mo/${LANG} DESTINATION ${LOCALE_DIR}/mo)
else ()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/lang/mo/${LANG} DESTINATION ${LOCALE_DIR})
endif ()
Expand Down
52 changes: 34 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.21)

add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party)

Expand Down Expand Up @@ -44,7 +44,7 @@ if (TILES)
${CATACLYSM_DDA_HEADERS})
target_include_directories(cataclysm-tiles-common INTERFACE ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(cataclysm-tiles-common third-party)
target_link_libraries(cataclysm-tiles-common PUBLIC third-party)

if (WIN32)
add_definitions(-DUSE_WINMAIN)
Expand Down Expand Up @@ -81,7 +81,7 @@ if (TILES)
endif ()

if (CMAKE_THREAD_LIBS_INIT)
target_link_libraries(cataclysm-tiles-common ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(cataclysm-tiles-common PUBLIC ${CMAKE_THREAD_LIBS_INIT})
endif ()

if (NOT DYNAMIC_LINKING)
Expand All @@ -91,44 +91,60 @@ if (TILES)
${PNG_INCLUDE_DIRS}
${JPEG_INCLUDE_DIR}
${BZIP2_INCLUDE_DIR})
target_link_libraries(cataclysm-tiles-common
target_link_libraries(cataclysm-tiles-common PUBLIC
${FREETYPE_LIBRARIES}
${PNG_LIBRARIES}
${JPEG_LIBRARIES}
${BZIP2_LIBRARIES})
target_link_libraries(cataclysm-tiles-common PUBLIC SDL2::SDL2-static)
endif ()
target_include_directories(cataclysm-tiles-common PUBLIC
${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS})
target_link_libraries(cataclysm-tiles-common
target_link_libraries(cataclysm-tiles-common PUBLIC
${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${ZLIB_LIBRARIES})

if(TARGET SDL2::SDL2)
target_link_libraries(cataclysm-tiles-common PUBLIC SDL2::SDL2
SDL2::SDL2main
SDL2::SDL2_image
$<IF:$<TARGET_EXISTS:SDL2_ttf::SDL2_ttf>,SDL2_ttf::SDL2_ttf,SDL2_ttf::SDL2_ttf-static>)
endif()
if (SOUND)
if (VCPKG_MANIFEST_MODE)
find_package(Ogg REQUIRED)
find_package(Vorbis REQUIRED)
target_link_libraries(cataclysm-tiles-common PUBLIC SDL2_mixer::SDL2_mixer-static
Ogg::ogg
Vorbis::vorbis)
endif()
target_compile_definitions(cataclysm-tiles-common PUBLIC SDL_SOUND )
target_include_directories(cataclysm-tiles-common PUBLIC ${OGGVORBIS_INCLUDE_DIR})
target_link_libraries(cataclysm-tiles-common ${OGG_LIBRARY})
target_link_libraries(cataclysm-tiles-common ${VORBIS_LIBRARY})
target_link_libraries(cataclysm-tiles-common ${VORBISFILE_LIBRARY})
target_link_libraries(cataclysm-tiles-common PUBLIC ${OGG_LIBRARY})
target_link_libraries(cataclysm-tiles-common PUBLIC ${VORBIS_LIBRARY})
target_link_libraries(cataclysm-tiles-common PUBLIC ${VORBISFILE_LIBRARY})
target_include_directories(cataclysm-tiles-common PUBLIC ${SDL2_MIXER_INCLUDE_DIRS})
target_link_libraries(cataclysm-tiles-common ${SDL2_MIXER_LIBRARIES})
target_link_libraries(cataclysm-tiles-common PUBLIC ${SDL2_MIXER_LIBRARIES})
endif ()

if (WIN32)
# Global settings for Windows targets (at end)
target_link_libraries(cataclysm-tiles-common gdi32.lib)
target_link_libraries(cataclysm-tiles-common winmm.lib)
target_link_libraries(cataclysm-tiles-common imm32.lib)
target_link_libraries(cataclysm-tiles-common ole32.lib)
target_link_libraries(cataclysm-tiles-common oleaut32.lib)
target_link_libraries(cataclysm-tiles-common version.lib)
target_link_libraries(cataclysm-tiles-common setupapi.lib)
target_link_libraries(cataclysm-tiles-common PUBLIC gdi32.lib)
target_link_libraries(cataclysm-tiles-common PUBLIC winmm.lib)
target_link_libraries(cataclysm-tiles-common PUBLIC imm32.lib)
target_link_libraries(cataclysm-tiles-common PUBLIC ole32.lib)
target_link_libraries(cataclysm-tiles-common PUBLIC oleaut32.lib)
target_link_libraries(cataclysm-tiles-common PUBLIC version.lib)
target_link_libraries(cataclysm-tiles-common PUBLIC setupapi.lib)
if (BACKTRACE)
target_link_libraries(cataclysm-tiles-common dbghelp.lib)
target_link_libraries(cataclysm-tiles-common PUBLIC dbghelp.lib)
if (LIBBACKTRACE)
target_link_libraries(cataclysm-tiles-common PUBLIC backtrace)
endif ()
endif ()
endif ()

Expand Down

0 comments on commit 3c575e5

Please sign in to comment.