Skip to content

Commit

Permalink
windows build with vcpkg
Browse files Browse the repository at this point in the history
builds correctly on x64-windows with msvc compiler
  • Loading branch information
kkosciusz committed Jun 15, 2024
1 parent a9596c9 commit a851308
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 102 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ build_*
*.swp

/vsbuild/.vs/raceintospace/v16
CMakeUserPresets.json
.vscode
vcpkg_installed
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CXX_STANDARD requires more recent CMake
cmake_minimum_required (VERSION 3.1)
cmake_minimum_required (VERSION 3.21...3.29)
project(raceintospace VERSION 2.0.0)

enable_testing()
Expand All @@ -19,14 +19,16 @@ endif (WINDOWS)

# Require C++11
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
option(PBEM "Enable Play-by-EMail feature" ON)

string(TOLOWER "${CMAKE_BUILD_TYPE}" lc_CMAKE_BUILD_TYPE)
if("${lc_CMAKE_BUILD_TYPE}" STREQUAL "debug")
add_definitions(-DDEBUG)
endif("${lc_CMAKE_BUILD_TYPE}" STREQUAL "debug")

add_subdirectory(lib)
# add_subdirectory(lib)
add_subdirectory(src)
install(PROGRAMS icons/raceintospace.desktop DESTINATION share/applications)
install(FILES icons/raceintospace.xpm icons/raceintospace.png DESTINATION share/pixmaps)
Expand Down
16 changes: 15 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Here's where we build external libraries that we need for the game
# Use CMake to download and compile these projects
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.20)

include(ExternalProject)
include(Global.cmake)
Expand All @@ -26,6 +26,12 @@ if (BUILD_BOOST)
)

add_dependencies(libs ext_boost)
else (BUILD_BOOST)
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})
# find_package(Boost REQUIRED COMPONENTS format smart_ptr)
# target_link_libraries(main PRIVATE Boost::boost Boost::<lib1> Boost::<lib2> ...)
# add_dependencies(libs Boost::format Boost::smart_ptr)
endif (BUILD_BOOST)


Expand All @@ -49,6 +55,10 @@ if (BUILD_ZLIB)
)

add_dependencies(libs ext_zlib)
else (BUILD_ZLIB)
find_package(ZLIB REQUIRED)
# target_link_libraries(main PRIVATE ZLIB::ZLIB)
add_dependencies(libs ZLIB::ZLIB)
endif (BUILD_ZLIB)

###
Expand All @@ -72,6 +82,10 @@ if (BUILD_LIBPNG)
if (BUILD_ZLIB)
add_dependencies(ext_libpng ext_zlib)
endif (BUILD_ZLIB)
else (BUILD_LIBPNG)
find_package(PNG REQUIRED)
# target_link_libraries(main PRIVATE PNG::PNG)
add_dependencies(libs PNG::PNG)
endif (BUILD_LIBPNG)

###
Expand Down
20 changes: 10 additions & 10 deletions lib/Global.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ if (APPLE)
set(BUILD_LIBPNG true)
set(BUILD_CEREAL true)
elseif (WINDOWS)
set(BUILD_JSONCPP true)
set(BUILD_ZLIB true)
set(BUILD_LIBPNG true)
set(BUILD_XIPH true)
set(BUILD_PROTOBUF true)
set(BUILD_BOOST true)
set(BUILD_SDL true)
set(BUILD_CEREAL true)
set(BUILD_PHYSFS true)
set(BUILD_JSONCPP false)
set(BUILD_ZLIB false)
set(BUILD_LIBPNG false)
set(BUILD_XIPH false)
set(BUILD_PROTOBUF false)
set(BUILD_BOOST false)
set(BUILD_SDL false)
set(BUILD_CEREAL false)
set(BUILD_PHYSFS false)
endif ()

if (BUILD_BOOST)
# Boost_INCLUDE_DIR can remain unset, since it's already in the path
else (BUILD_BOOST)
find_package(Boost)
find_package(Boost REQUIRED)
endif (BUILD_BOOST)

if (BUILD_ZLIB)
Expand Down
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(CheckSymbolExists)
include(CheckFunctionExists)
include(TestBigEndian)

include(${PROJECT_SOURCE_DIR}/lib/Global.cmake)
# include(${PROJECT_SOURCE_DIR}/lib/Global.cmake)

if (NOT WINDOWS)
check_function_exists(mkdir HAVE_MKDIR)
Expand Down Expand Up @@ -63,7 +63,7 @@ configure_file(
include_directories(${PROJECT_BINARY_DIR}/config)

# build src/display
include("display/Global.cmake")
# include("display/Global.cmake")
add_subdirectory("display")

# build src/protobuf
Expand All @@ -73,4 +73,4 @@ add_subdirectory("protobuf")
add_subdirectory("game")

# build the targets in src/utils too
add_subdirectory("utils")
# add_subdirectory("utils")
14 changes: 10 additions & 4 deletions src/display/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
include_directories(${PROJECT_SOURCE_DIR}/src)
# include_directories(${PROJECT_SOURCE_DIR}/src)

include(${PROJECT_SOURCE_DIR}/lib/Global.cmake)
# include(${PROJECT_SOURCE_DIR}/lib/Global.cmake)

find_package(SDL REQUIRED)
find_package(Boost REQUIRED)
find_package(PNG REQUIRED)
add_library(
raceintospace_display STATIC
graphics.cpp
Expand All @@ -11,6 +14,9 @@ add_library(
palettized_surface.cpp
surface.cpp
)
target_link_libraries(raceintospace_display ${SDL_LIBRARY})
target_link_libraries(raceintospace_display PUBLIC SDL::SDL)
target_link_libraries(raceintospace_display PRIVATE PNG::PNG)
target_include_directories(raceintospace_display PUBLIC ${Boost_INCLUDE_DIR})
target_include_directories(raceintospace_display PUBLIC ${PROJECT_SOURCE_DIR}/src)

add_dependencies(raceintospace_display libs)
# add_dependencies(raceintospace_display)
58 changes: 29 additions & 29 deletions src/game/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_BINARY_DIR}/config)
include_directories(${PROJECT_SOURCE_DIR}/src/game)
include_directories(${raceintospace_protobuf_include_dir})
if (JsonCPP_INCLUDE_DIR)
include_directories(${JsonCPP_INCLUDE_DIR})
endif (JsonCPP_INCLUDE_DIR)

# Make sure we can access our local includes
include(${PROJECT_SOURCE_DIR}/lib/Global.cmake)

if (PBEM)
add_definitions(-DALLOW_PBEM=1)
endif (PBEM)
Expand Down Expand Up @@ -100,10 +89,21 @@ set(game_sources
set (ui_sources
)

find_package(Ogg REQUIRED)
find_package(unofficial-theora CONFIG REQUIRED)
find_package(PhysFS CONFIG REQUIRED)
find_package(JsonCPP REQUIRED)
find_package(cereal REQUIRED)
find_package(Boost REQUIRED)
find_package(ZLIB REQUIRED)

set(game_libraries
${SDL_LIBRARY} ogg vorbis theora protobuf
${JsonCPP_LIBRARY} ${Physfs_LIBRARY} ${zlib_LIBRARY}
raceintospace_display ${raceintospace_display_libraries}
Ogg::ogg
unofficial::theora::theoradec
JsonCpp::JsonCpp
PhysFS::PhysFS
ZLIB::ZLIB
raceintospace_display
raceintospace_protobuf
)

Expand All @@ -120,19 +120,19 @@ endif()
# populated with platform-specific files.
# Not using (file GLOB ...) because CMake documentation recommends
# against it (https://cmake.org/cmake/help/v3.14/command/file.html)
set(test_dir ${PROJECT_SOURCE_DIR}/test)
set(test_sources
music_none.cpp
${test_dir}/game/dummy_test.cpp
${test_dir}/game/mission_test.cpp
${test_dir}/game/downgrade_test.cpp
${test_dir}/game/roster_test.cpp
)
# set(test_dir ${PROJECT_SOURCE_DIR}/test)
# set(test_sources
# music_none.cpp
# ${test_dir}/game/dummy_test.cpp
# ${test_dir}/game/mission_test.cpp
# ${test_dir}/game/downgrade_test.cpp
# ${test_dir}/game/roster_test.cpp
# )

add_executable(game_test ../../test/test_main.cpp ${test_sources} ${game_sources})
set_target_properties(game_test PROPERTIES COMPILE_FLAGS "-DBOOST_TEST_NO_LIB=1")
target_link_libraries(game_test ${game_libraries})
add_test(
NAME game_test
COMMAND game_test --catch_system_errors=yes
)
# add_executable(game_test ../../test/test_main.cpp ${test_sources} ${game_sources})
# set_target_properties(game_test PROPERTIES COMPILE_FLAGS "-DBOOST_TEST_NO_LIB=1")
# target_link_libraries(game_test ${game_libraries})
# add_test(
# NAME game_test
# COMMAND game_test --catch_system_errors=yes
# )
4 changes: 2 additions & 2 deletions src/game/admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ void LoadGame(const char *filename)
SaveFileHdr header;
unsigned char magic[2];
unsigned char *cbuf, *buf;
size_t csize, usize = 0;
uLongf usize = 0;
int i, ok, offset;

FILE *fin = sOpen(filename, "rb", FT_SAVE);
Expand All @@ -1591,7 +1591,7 @@ void LoadGame(const char *filename)
fseek(fin, -2, SEEK_CUR);

if (magic[0] == 0x78 && magic[1] == 0xDA) { // zlib magic numbers
csize = fileLength - sizeof(header);
size_t csize = fileLength - sizeof(header);
cbuf = (unsigned char *) malloc(csize);
buf = (unsigned char *) malloc(usize);
assert(cbuf && buf);
Expand Down
2 changes: 0 additions & 2 deletions src/game/platform_windows/fake_unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;

#define snprintf _snprintf

// this really doesn't belong here...
#define __func__ __FUNCTION__

Expand Down
9 changes: 6 additions & 3 deletions src/game/platform_windows/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/platform_windows)

# Add the platform-specific source files needed for testing
list(APPEND ui_sources music_vorbis.cpp)
list(APPEND game_libraries Vorbis::vorbis)

set(app "Race Into Space")
find_package(Vorbis CONFIG REQUIRED)

set(app "raceintospace")

add_executable(${app}
${game_sources}
Expand All @@ -24,6 +27,6 @@ add_executable(${app}
platform_windows/main.c
)

target_link_libraries(${app} ${game_libraries})
target_link_libraries(${app} PRIVATE ${game_libraries})

add_dependencies(${app} libs)
# add_dependencies(${app} libs)
51 changes: 6 additions & 45 deletions src/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,8 @@
include_directories(${PROJECT_SOURCE_DIR}/src)
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
add_library(raceintospace_protobuf raceintospace.proto)
protobuf_generate(TARGET raceintospace_protobuf)
target_include_directories(raceintospace_protobuf INTERFACE ${CMAKE_CURRENT_BINARY_DIR})

# From http://www.cmake.org/pipermail/cmake/2008-September/023963.html
FUNCTION(WRAP_PROTO VAR)
IF (NOT ARGN)
MESSAGE(SEND_ERROR "Error: WRAP PROTO called without any proto files")
RETURN()
ENDIF(NOT ARGN)
# set(raceintospace_protobuf_include_dir ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)

if(TARGET ext_protobuf)
set(protoc ${LocalPrefix}/bin/protoc)
set(deps ext_protobuf)
else()
set(protoc protoc)
set(deps)
endif()

SET(INCL)
SET(${VAR})
FOREACH(FIL ${ARGN})
GET_FILENAME_COMPONENT(ABS_FIL ${FIL} ABSOLUTE)
GET_FILENAME_COMPONENT(FIL_WE ${FIL} NAME_WE)
LIST(APPEND ${VAR} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
LIST(APPEND INCL "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")

ADD_CUSTOM_COMMAND(
OUTPUT ${${VAR}} ${INCL}
COMMAND ${protoc}
ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
DEPENDS ${ABS_FIL} ${deps}
COMMENT "Running protocol buffer compiler on ${FIL}"
VERBATIM )
ENDFOREACH(FIL)

SET(${VAR} ${${VAR}} PARENT_SCOPE)
ENDFUNCTION(WRAP_PROTO)

wrap_proto(raceintospace_proto_impl raceintospace.proto)

add_library(
raceintospace_protobuf STATIC
${raceintospace_proto_impl}
)

set(raceintospace_protobuf_include_dir ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)

add_dependencies(raceintospace_protobuf libs)
2 changes: 1 addition & 1 deletion src/protobuf/raceintospace.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

syntax = "proto2";
package raceintospace;

message Equipment {
Expand Down
14 changes: 14 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "943c5ef1c8f6b5e6ced092b242c8299caae2ff01",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}
18 changes: 18 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"dependencies": [
"boost-algorithm",
"boost-format",
"boost-foreach",
"boost-smart-ptr",
"libpng",
"zlib",
"cereal",
"protobuf",
"libtheora",
"libogg",
"libvorbis",
"sdl1",
"physfs",
"jsoncpp"
]
}

0 comments on commit a851308

Please sign in to comment.