From b69478df6dfeedd1a9ee1fae5676397a80b1ac96 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Tue, 1 May 2018 21:20:44 -0400 Subject: [PATCH 01/24] Ignore CMake build directories --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1bdabf40..fcd9394a 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ DOOM*.pcx HTIC*.pcx HEXEN*.pcx STRIFE*.pcx +/build* # These are the default patterns globally ignored by Subversion: *.o From b9422484fbfbc467645a75d17f30227fb2c4a260 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Tue, 1 May 2018 23:10:46 -0400 Subject: [PATCH 02/24] Initial stab at SDL2 and textscreen --- CMakeLists.txt | 10 +++++++ cmake/FindSDL2.cmake | 53 ++++++++++++++++++++++++++++++++++++++ cmake/FindSDL2_mixer.cmake | 0 cmake/FindSDL2_net.cmake | 0 textscreen/CMakeLists.txt | 26 +++++++++++++++++++ 5 files changed, 89 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/FindSDL2.cmake create mode 100644 cmake/FindSDL2_mixer.cmake create mode 100644 cmake/FindSDL2_net.cmake create mode 100644 textscreen/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..2be647ed --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,10 @@ +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +cmake_minimum_required(VERSION 3.9.3) +project("Chocolate Doom" VERSION 3.0.0 LANGUAGES C) + +find_package(SDL2 2.0.1) +find_package(SDL2_mixer 2.0.0) +find_package(SDL2_net 2.0.0) + +add_subdirectory(textscreen) diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 00000000..218a67a1 --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,53 @@ +# Currently works with the following generators: +# - Visual Studio + +set(SDL2_DIR "${SDL2_DIR}" CACHE PATH "Location of SDL2 library directory") + +find_path(SDL2_INCLUDE_DIR "SDL_version.h" + PATHS "${SDL2_DIR}/include") + +if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") + file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}") + set(SDL2_VERSION "${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}") + unset(SDL2_VERSION_MAJOR_LINE) + unset(SDL2_VERSION_MINOR_LINE) + unset(SDL2_VERSION_PATCH_LINE) + unset(SDL2_VERSION_MAJOR) + unset(SDL2_VERSION_MINOR) + unset(SDL2_VERSION_PATCH) +endif() + +if(CMAKE_SIZEOF_VOID_P STREQUAL 8) + find_library(SDL2_LIBRARY "SDL2" + PATHS "${SDL2_DIR}/lib/x64") + find_library(SDL2_MAIN_LIBRARY "SDL2main" + PATHS "${SDL2_DIR}/lib/x64") +else() + find_library(SDL2_LIBRARY "SDL2" + PATHS "${SDL2_DIR}/lib/x86") + find_library(SDL2_MAIN_LIBRARY "SDL2main" + PATHS "${SDL2_DIR}/lib/x86") +endif() +set(SDL2_LIBRARIES "${SDL2_MAIN_LIBRARY}" "${SDL2_LIBRARY}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2 + FOUND_VAR SDL2_FOUND + REQUIRED_VARS SDL2_INCLUDE_DIR SDL2_LIBRARIES + VERSION_VAR SDL2_VERSION +) + +if(SDL2_FOUND) + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + set_target_properties(SDL2::SDL2 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + IMPORTED_LOCATION "${SDL2_LIBRARY}") + add_library(SDL2::SDL2main UNKNOWN IMPORTED) + set_target_properties(SDL2::SDL2main PROPERTIES + IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}") +endif() diff --git a/cmake/FindSDL2_mixer.cmake b/cmake/FindSDL2_mixer.cmake new file mode 100644 index 00000000..e69de29b diff --git a/cmake/FindSDL2_net.cmake b/cmake/FindSDL2_net.cmake new file mode 100644 index 00000000..e69de29b diff --git a/textscreen/CMakeLists.txt b/textscreen/CMakeLists.txt new file mode 100644 index 00000000..f255cbc4 --- /dev/null +++ b/textscreen/CMakeLists.txt @@ -0,0 +1,26 @@ +add_library(textscreen + textscreen.h + txt_conditional.c txt_conditional.h + txt_checkbox.c txt_checkbox.h + txt_desktop.c txt_desktop.h + txt_dropdown.c txt_dropdown.h + txt_fileselect.c txt_fileselect.h + txt_gui.c txt_gui.h + txt_inputbox.c txt_inputbox.h + txt_io.c txt_io.h + txt_main.h + txt_button.c txt_button.h + txt_label.c txt_label.h + txt_radiobutton.c txt_radiobutton.h + txt_scrollpane.c txt_scrollpane.h + txt_separator.c txt_separator.h + txt_spinctrl.c txt_spinctrl.h + txt_sdl.c txt_sdl.h + txt_strut.c txt_strut.h + txt_table.c txt_table.h + txt_utf8.c txt_utf8.h + txt_widget.c txt_widget.h + txt_window.c txt_window.h + txt_window_action.c txt_window_action.h) +target_include_directories(textscreen PRIVATE "../src/") +target_link_libraries(textscreen SDL2::SDL2) From 5b30a0ac1f903b7365ac9134eed74a6b1664de9d Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Wed, 2 May 2018 18:43:39 -0400 Subject: [PATCH 03/24] SDL2_mixer and midiproc --- CMakeLists.txt | 15 ++++++++ cmake/FindSDL2.cmake | 35 +++++++++++++++++ cmake/FindSDL2_mixer.cmake | 79 ++++++++++++++++++++++++++++++++++++++ config.cmake.h | 3 ++ midiproc/CMakeLists.txt | 4 ++ 5 files changed, 136 insertions(+) create mode 100644 config.cmake.h create mode 100644 midiproc/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 2be647ed..d2607108 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,23 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") cmake_minimum_required(VERSION 3.9.3) project("Chocolate Doom" VERSION 3.0.0 LANGUAGES C) +# AC_INIT variables +set(PACKAGE_NAME "${PROJECT_NAME}") +set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") + +string(REGEX REPLACE " Doom$" "" PACKAGE_SHORTNAME "${PACKAGE_NAME}") + find_package(SDL2 2.0.1) find_package(SDL2_mixer 2.0.0) find_package(SDL2_net 2.0.0) +# Without a hyphen. This is used for the bash-completion scripts. +string(TOLOWER "${PACKAGE_SHORTNAME}" PROGRAM_SPREFIX) + +# With a hyphen, used almost everywhere else. +set(PROGRAM_PREFIX "${PROGRAM_SPREFIX}-") + +configure_file(config.cmake.h config.h) + +add_subdirectory(midiproc) add_subdirectory(textscreen) diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake index 218a67a1..d2935f48 100644 --- a/cmake/FindSDL2.cmake +++ b/cmake/FindSDL2.cmake @@ -1,11 +1,42 @@ +# FindSDL2.cmake +# +# Copyright (c) 2018, Alex Mayfield +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# # Currently works with the following generators: # - Visual Studio +# Cache variable that allows you to point CMake at a directory containing +# an extracted development library. set(SDL2_DIR "${SDL2_DIR}" CACHE PATH "Location of SDL2 library directory") +# Find the include directory. find_path(SDL2_INCLUDE_DIR "SDL_version.h" PATHS "${SDL2_DIR}/include") +# Find the version. Taken and modified from CMake's FindSDL.cmake. if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") @@ -22,6 +53,7 @@ if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") unset(SDL2_VERSION_PATCH) endif() +# Find the SDL2 and SDL2main libraries if(CMAKE_SIZEOF_VOID_P STREQUAL 8) find_library(SDL2_LIBRARY "SDL2" PATHS "${SDL2_DIR}/lib/x64") @@ -43,10 +75,13 @@ find_package_handle_standard_args(SDL2 ) if(SDL2_FOUND) + # SDL2 imported target. add_library(SDL2::SDL2 UNKNOWN IMPORTED) set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" IMPORTED_LOCATION "${SDL2_LIBRARY}") + + # SDL2main imported target. add_library(SDL2::SDL2main UNKNOWN IMPORTED) set_target_properties(SDL2::SDL2main PROPERTIES IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}") diff --git a/cmake/FindSDL2_mixer.cmake b/cmake/FindSDL2_mixer.cmake index e69de29b..446f1fb0 100644 --- a/cmake/FindSDL2_mixer.cmake +++ b/cmake/FindSDL2_mixer.cmake @@ -0,0 +1,79 @@ +# FindSDL2_mixer.cmake +# +# Copyright (c) 2018, Alex Mayfield +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Currently works with the following generators: +# - Visual Studio + +# Cache variable that allows you to point CMake at a directory containing +# an extracted development library. +set(SDL2_MIXER_DIR "${SDL2_MIXER_DIR}" CACHE PATH "Location of SDL2_mixer library directory") + +# Find the include directory. +find_path(SDL2_MIXER_INCLUDE_DIR "SDL_mixer.h" + PATHS "${SDL2_MIXER_DIR}/include") + +# Find the version. Taken and modified from CMake's FindSDL.cmake. +if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") + set(SDL2_MIXER_VERSION "${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}") + unset(SDL2_MIXER_VERSION_MAJOR_LINE) + unset(SDL2_MIXER_VERSION_MINOR_LINE) + unset(SDL2_MIXER_VERSION_PATCH_LINE) + unset(SDL2_MIXER_VERSION_MAJOR) + unset(SDL2_MIXER_VERSION_MINOR) + unset(SDL2_MIXER_VERSION_PATCH) +endif() + +# Find the library. +if(CMAKE_SIZEOF_VOID_P STREQUAL 8) + find_library(SDL2_MIXER_LIBRARY "SDL2_mixer" + PATHS "${SDL2_MIXER_DIR}/lib/x64") +else() + find_library(SDL2_MIXER_LIBRARY "SDL2" + PATHS "${SDL2_MIXER_DIR}/lib/x86") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2_mixer + FOUND_VAR SDL2_MIXER_FOUND + REQUIRED_VARS SDL2_MIXER_INCLUDE_DIR SDL2_MIXER_LIBRARY + VERSION_VAR SDL2_MIXER_VERSION +) + +if(SDL2_MIXER_FOUND) + # Imported target. + add_library(SDL2::mixer UNKNOWN IMPORTED) + set_target_properties(SDL2::mixer PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES SDL2::SDL2 + IMPORTED_LOCATION "${SDL2_MIXER_LIBRARY}") +endif() diff --git a/config.cmake.h b/config.cmake.h new file mode 100644 index 00000000..ee30c96c --- /dev/null +++ b/config.cmake.h @@ -0,0 +1,3 @@ +#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" +#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" +#cmakedefine PROGRAM_PREFIX "@PROGRAM_PREFIX@" diff --git a/midiproc/CMakeLists.txt b/midiproc/CMakeLists.txt new file mode 100644 index 00000000..1b6e27c5 --- /dev/null +++ b/midiproc/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable("${PROGRAM_PREFIX}midiproc" buffer.c buffer.h main.c proto.h) +target_include_directories("${PROGRAM_PREFIX}midiproc" + PRIVATE "../src/" "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries("${PROGRAM_PREFIX}midiproc" SDL2::SDL2main SDL2::mixer) From aebcec00b2dbab0a8c305b2f55f5a31735b08139 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Wed, 2 May 2018 20:20:28 -0400 Subject: [PATCH 04/24] opl and pcsound libraries --- CMakeLists.txt | 2 ++ opl/CMakeLists.txt | 13 +++++++++++++ pcsound/CMakeLists.txt | 9 +++++++++ 3 files changed, 24 insertions(+) create mode 100644 opl/CMakeLists.txt create mode 100644 pcsound/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d2607108..7bfbb91d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,4 +22,6 @@ set(PROGRAM_PREFIX "${PROGRAM_SPREFIX}-") configure_file(config.cmake.h config.h) add_subdirectory(midiproc) +add_subdirectory(opl) +add_subdirectory(pcsound) add_subdirectory(textscreen) diff --git a/opl/CMakeLists.txt b/opl/CMakeLists.txt new file mode 100644 index 00000000..cd3df7d8 --- /dev/null +++ b/opl/CMakeLists.txt @@ -0,0 +1,13 @@ +add_library(opl STATIC + opl_internal.h + opl.c opl.h + opl_linux.c + opl_obsd.c + opl_queue.c opl_queue.h + opl_sdl.c + opl_timer.c opl_timer.h + opl_win32.c + ioperm_sys.c ioperm_sys.h + opl3.c opl3.h) +target_include_directories(opl PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries(opl SDL2::mixer) diff --git a/pcsound/CMakeLists.txt b/pcsound/CMakeLists.txt new file mode 100644 index 00000000..fe059988 --- /dev/null +++ b/pcsound/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(pcsound STATIC + pcsound.c pcsound.h + pcsound_bsd.c + pcsound_sdl.c + pcsound_linux.c + pcsound_win32.c + pcsound_internal.h) +target_include_directories(pcsound PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries(pcsound SDL2::mixer) From 097f3b07f2038e915329f6d2965b2b6002d56b18 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Wed, 2 May 2018 20:48:14 -0400 Subject: [PATCH 05/24] SDL2_net and chocolate-server --- CMakeLists.txt | 7 ++-- cmake/FindSDL2_net.cmake | 79 ++++++++++++++++++++++++++++++++++++++ src/.gitignore | 1 + src/CMakeLists.txt | 32 +++++++++++++++ src/doom/CMakeLists.txt | 0 src/heretic/CMakeLists.txt | 0 src/hexen/CMakeLists.txt | 0 src/setup/CMakeLists.txt | 0 src/strife/CMakeLists.txt | 0 9 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 src/CMakeLists.txt create mode 100644 src/doom/CMakeLists.txt create mode 100644 src/heretic/CMakeLists.txt create mode 100644 src/hexen/CMakeLists.txt create mode 100644 src/setup/CMakeLists.txt create mode 100644 src/strife/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bfbb91d..90f71526 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,6 @@ set(PROGRAM_PREFIX "${PROGRAM_SPREFIX}-") configure_file(config.cmake.h config.h) -add_subdirectory(midiproc) -add_subdirectory(opl) -add_subdirectory(pcsound) -add_subdirectory(textscreen) +foreach(SUBDIR textscreen midiproc opl pcsound src) + add_subdirectory("${SUBDIR}") +endforeach() diff --git a/cmake/FindSDL2_net.cmake b/cmake/FindSDL2_net.cmake index e69de29b..87ab8338 100644 --- a/cmake/FindSDL2_net.cmake +++ b/cmake/FindSDL2_net.cmake @@ -0,0 +1,79 @@ +# FindSDL2_net.cmake +# +# Copyright (c) 2018, Alex Mayfield +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Currently works with the following generators: +# - Visual Studio + +# Cache variable that allows you to point CMake at a directory containing +# an extracted development library. +set(SDL2_NET_DIR "${SDL2_NET_DIR}" CACHE PATH "Location of SDL2_net library directory") + +# Find the include directory. +find_path(SDL2_NET_INCLUDE_DIR "SDL_net.h" + PATHS "${SDL2_NET_DIR}/include") + +# Find the version. Taken and modified from CMake's FindSDL.cmake. +if(SDL2_NET_INCLUDE_DIR AND EXISTS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h") + file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MAJOR "${SDL2_NET_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MINOR "${SDL2_NET_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_PATCH "${SDL2_NET_VERSION_PATCH_LINE}") + set(SDL2_NET_VERSION "${SDL2_NET_VERSION_MAJOR}.${SDL2_NET_VERSION_MINOR}.${SDL2_NET_VERSION_PATCH}") + unset(SDL2_NET_VERSION_MAJOR_LINE) + unset(SDL2_NET_VERSION_MINOR_LINE) + unset(SDL2_NET_VERSION_PATCH_LINE) + unset(SDL2_NET_VERSION_MAJOR) + unset(SDL2_NET_VERSION_MINOR) + unset(SDL2_NET_VERSION_PATCH) +endif() + +# Find the library. +if(CMAKE_SIZEOF_VOID_P STREQUAL 8) + find_library(SDL2_NET_LIBRARY "SDL2_net" + PATHS "${SDL2_NET_DIR}/lib/x64") +else() + find_library(SDL2_NET_LIBRARY "SDL2" + PATHS "${SDL2_NET_DIR}/lib/x86") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2_net + FOUND_VAR SDL2_NET_FOUND + REQUIRED_VARS SDL2_NET_INCLUDE_DIR SDL2_NET_LIBRARY + VERSION_VAR SDL2_NET_VERSION +) + +if(SDL2_NET_FOUND) + # Imported target. + add_library(SDL2::net UNKNOWN IMPORTED) + set_target_properties(SDL2::net PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_NET_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES SDL2::SDL2 + IMPORTED_LOCATION "${SDL2_NET_LIBRARY}") +endif() diff --git a/src/.gitignore b/src/.gitignore index 6986ecfe..556dfeaf 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -16,6 +16,7 @@ chocolate-setup *.exe *.desktop *.txt +!CMakeLists.txt *.appdata.xml tags TAGS diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..5eacff41 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,32 @@ +foreach(SUBDIR doom heretic hexen strife setup) + add_subdirectory("${SUBDIR}") +endforeach() + +# Common source files used by absolutely everything: + +set(COMMON_SOURCE_FILES + i_main.c + i_system.c i_system.h + m_argv.c m_argv.h + m_misc.c m_misc.h) + +# Dedicated server (chocolate-server): + +set(DEDSERV_FILES + d_dedicated.c + d_mode.c d_mode.h + i_timer.c i_timer.h + net_common.c net_common.h + net_dedicated.c net_dedicated.h + net_io.c net_io.h + net_packet.c net_packet.h + net_sdl.c net_sdl.h + net_query.c net_query.h + net_server.c net_server.h + net_structrw.c net_structrw.h + z_native.c z_zone.h) + +add_executable("${PROGRAM_PREFIX}server" ${COMMON_SOURCE_FILES} ${DEDSERV_FILES}) +target_include_directories("${PROGRAM_PREFIX}server" + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries("${PROGRAM_PREFIX}server" SDL2::SDL2main SDL2::net) diff --git a/src/doom/CMakeLists.txt b/src/doom/CMakeLists.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/heretic/CMakeLists.txt b/src/heretic/CMakeLists.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/hexen/CMakeLists.txt b/src/hexen/CMakeLists.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/setup/CMakeLists.txt b/src/setup/CMakeLists.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/strife/CMakeLists.txt b/src/strife/CMakeLists.txt new file mode 100644 index 00000000..e69de29b From f8810f763c304449fbe81d792da13013aadb6e8d Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Wed, 2 May 2018 21:23:00 -0400 Subject: [PATCH 06/24] Chocolate Doom now builds --- opl/CMakeLists.txt | 4 +- pcsound/CMakeLists.txt | 4 +- src/CMakeLists.txt | 82 +++++++++++++++++++++++++++++++++++++++ src/doom/CMakeLists.txt | 71 +++++++++++++++++++++++++++++++++ textscreen/CMakeLists.txt | 4 +- 5 files changed, 162 insertions(+), 3 deletions(-) diff --git a/opl/CMakeLists.txt b/opl/CMakeLists.txt index cd3df7d8..f88a12a1 100644 --- a/opl/CMakeLists.txt +++ b/opl/CMakeLists.txt @@ -9,5 +9,7 @@ add_library(opl STATIC opl_win32.c ioperm_sys.c ioperm_sys.h opl3.c opl3.h) -target_include_directories(opl PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_include_directories(opl + INTERFACE "." + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") target_link_libraries(opl SDL2::mixer) diff --git a/pcsound/CMakeLists.txt b/pcsound/CMakeLists.txt index fe059988..7988b8bd 100644 --- a/pcsound/CMakeLists.txt +++ b/pcsound/CMakeLists.txt @@ -5,5 +5,7 @@ add_library(pcsound STATIC pcsound_linux.c pcsound_win32.c pcsound_internal.h) -target_include_directories(pcsound PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_include_directories(pcsound + INTERFACE "." + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") target_link_libraries(pcsound SDL2::mixer) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5eacff41..83fe0eba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,3 +30,85 @@ add_executable("${PROGRAM_PREFIX}server" ${COMMON_SOURCE_FILES} ${DEDSERV_FILES} target_include_directories("${PROGRAM_PREFIX}server" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") target_link_libraries("${PROGRAM_PREFIX}server" SDL2::SDL2main SDL2::net) + +# Source files used by the game binaries (chocolate-doom, etc.) + +set(GAME_SOURCE_FILES + aes_prng.c aes_prng.h + d_event.c d_event.h + doomkeys.h + doomtype.h + d_iwad.c d_iwad.h + d_loop.c d_loop.h + d_mode.c d_mode.h + d_ticcmd.h + deh_str.c deh_str.h + gusconf.c gusconf.h + i_cdmus.c i_cdmus.h + i_endoom.c i_endoom.h + i_input.c i_input.h + i_joystick.c i_joystick.h + i_swap.h + i_midipipe.c i_midipipe.h + i_oplmusic.c + i_pcsound.c + i_sdlmusic.c + i_sdlsound.c + i_sound.c i_sound.h + i_timer.c i_timer.h + i_video.c i_video.h + i_videohr.c i_videohr.h + midifile.c midifile.h + mus2mid.c mus2mid.h + m_bbox.c m_bbox.h + m_cheat.c m_cheat.h + m_config.c m_config.h + m_controls.c m_controls.h + m_fixed.c m_fixed.h + net_client.c net_client.h + net_common.c net_common.h + net_dedicated.c net_dedicated.h + net_defs.h + net_gui.c net_gui.h + net_io.c net_io.h + net_loop.c net_loop.h + net_packet.c net_packet.h + net_query.c net_query.h + net_sdl.c net_sdl.h + net_server.c net_server.h + net_structrw.c net_structrw.h + sha1.c sha1.h + memio.c memio.h + tables.c tables.h + v_diskicon.c v_diskicon.h + v_video.c v_video.h + v_patch.h + w_checksum.c w_checksum.h + w_main.c w_main.h + w_wad.c w_wad.h + w_file.c w_file.h + w_file_stdc.c + w_file_posix.c + w_file_win32.c + w_merge.c w_merge.h + z_zone.c z_zone.h) + +set(DEHACKED_SOURCE_FILES + deh_defs.h + deh_io.c deh_io.h + deh_main.c deh_main.h + deh_mapping.c deh_mapping.h + deh_text.c) + +# Some games support dehacked patches, some don't: + +set(SOURCE_FILES ${COMMON_SOURCE_FILES} ${GAME_SOURCE_FILES}) +set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES}) + +set(EXTRA_LIBS textscreen pcsound opl SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net) + +add_executable("${PROGRAM_PREFIX}doom" ${SOURCE_FILES_WITH_DEH}) + +target_include_directories("${PROGRAM_PREFIX}doom" + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries("${PROGRAM_PREFIX}doom" doom ${EXTRA_LIBS}) diff --git a/src/doom/CMakeLists.txt b/src/doom/CMakeLists.txt index e69de29b..0310910a 100644 --- a/src/doom/CMakeLists.txt +++ b/src/doom/CMakeLists.txt @@ -0,0 +1,71 @@ +add_library(doom STATIC + am_map.c am_map.h + deh_ammo.c + deh_bexstr.c + deh_cheat.c + deh_doom.c + deh_frame.c + deh_misc.c deh_misc.h + deh_ptr.c + deh_sound.c + deh_thing.c + deh_weapon.c + d_englsh.h + d_items.c d_items.h + d_main.c d_main.h + d_net.c + doomdata.h + doomdef.c doomdef.h + doomstat.c doomstat.h + d_player.h + dstrings.c dstrings.h + d_textur.h + d_think.h + f_finale.c f_finale.h + f_wipe.c f_wipe.h + g_game.c g_game.h + hu_lib.c hu_lib.h + hu_stuff.c hu_stuff.h + info.c info.h + m_menu.c m_menu.h + m_random.c m_random.h + p_ceilng.c + p_doors.c + p_enemy.c + p_floor.c + p_inter.c p_inter.h + p_lights.c + p_local.h + p_map.c + p_maputl.c + p_mobj.c p_mobj.h + p_plats.c + p_pspr.c p_pspr.h + p_saveg.c p_saveg.h + p_setup.c p_setup.h + p_sight.c + p_spec.c p_spec.h + p_switch.c + p_telept.c + p_tick.c p_tick.h + p_user.c + r_bsp.c r_bsp.h + r_data.c r_data.h + r_defs.h + r_draw.c r_draw.h + r_local.h + r_main.c r_main.h + r_plane.c r_plane.h + r_segs.c r_segs.h + r_sky.c r_sky.h + r_state.h + r_things.c r_things.h + s_sound.c s_sound.h + sounds.c sounds.h + statdump.c statdump.h + st_lib.c st_lib.h + st_stuff.c st_stuff.h + wi_stuff.c wi_stuff.h) + +target_include_directories(doom PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../") +target_link_libraries(doom SDL2::SDL2 SDL2::mixer SDL2::net) diff --git a/textscreen/CMakeLists.txt b/textscreen/CMakeLists.txt index f255cbc4..bf9fa1fb 100644 --- a/textscreen/CMakeLists.txt +++ b/textscreen/CMakeLists.txt @@ -22,5 +22,7 @@ add_library(textscreen txt_widget.c txt_widget.h txt_window.c txt_window.h txt_window_action.c txt_window_action.h) -target_include_directories(textscreen PRIVATE "../src/") +target_include_directories(textscreen + INTERFACE "." + PRIVATE "../src/") target_link_libraries(textscreen SDL2::SDL2) From 8101009bbacb0feadead89ef36419ba15a33b171 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Fri, 4 May 2018 17:46:19 -0400 Subject: [PATCH 07/24] CMake now works on Linux It uses pkg-config to obtain hints about where the libraries are. --- CMakeLists.txt | 7 ++++++- cmake/FindSDL2.cmake | 19 ++++++++++++++----- cmake/FindSDL2_mixer.cmake | 17 +++++++++++++---- cmake/FindSDL2_net.cmake | 17 +++++++++++++---- config.cmake.h | 4 ++++ midiproc/CMakeLists.txt | 10 ++++++---- 6 files changed, 56 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90f71526..e1157044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,11 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -cmake_minimum_required(VERSION 3.9.3) +cmake_minimum_required(VERSION 3.7.2) project("Chocolate Doom" VERSION 3.0.0 LANGUAGES C) # AC_INIT variables set(PACKAGE_NAME "${PROJECT_NAME}") +set(PACKAGE_TARNAME "chocolate-doom") set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") string(REGEX REPLACE " Doom$" "" PACKAGE_SHORTNAME "${PACKAGE_NAME}") @@ -13,6 +14,10 @@ find_package(SDL2 2.0.1) find_package(SDL2_mixer 2.0.0) find_package(SDL2_net 2.0.0) +include(CheckFunctionExists) +check_function_exists(strcasecmp HAVE_DECL_STRCASECMP) +check_function_exists(strncasecmp HAVE_DECL_STRNCASECMP) + # Without a hyphen. This is used for the bash-completion scripts. string(TOLOWER "${PACKAGE_SHORTNAME}" PROGRAM_SPREFIX) diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake index d2935f48..bf7a3d78 100644 --- a/cmake/FindSDL2.cmake +++ b/cmake/FindSDL2.cmake @@ -26,15 +26,23 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Currently works with the following generators: +# - Unix Makefiles +# - Ninja # - Visual Studio # Cache variable that allows you to point CMake at a directory containing # an extracted development library. set(SDL2_DIR "${SDL2_DIR}" CACHE PATH "Location of SDL2 library directory") +# Use pkg-config to find library locations in *NIX environments. +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_SDL2 QUIET sdl2) +endif() + # Find the include directory. find_path(SDL2_INCLUDE_DIR "SDL_version.h" - PATHS "${SDL2_DIR}/include") + HINTS "${SDL2_DIR}/include" ${PC_SDL2_INCLUDE_DIRS}) # Find the version. Taken and modified from CMake's FindSDL.cmake. if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") @@ -56,14 +64,14 @@ endif() # Find the SDL2 and SDL2main libraries if(CMAKE_SIZEOF_VOID_P STREQUAL 8) find_library(SDL2_LIBRARY "SDL2" - PATHS "${SDL2_DIR}/lib/x64") + HINTS "${SDL2_DIR}/lib/x64" ${PC_SDL2_LIBRARY_DIRS}) find_library(SDL2_MAIN_LIBRARY "SDL2main" - PATHS "${SDL2_DIR}/lib/x64") + HINTS "${SDL2_DIR}/lib/x64" ${PC_SDL2_LIBRARY_DIRS}) else() find_library(SDL2_LIBRARY "SDL2" - PATHS "${SDL2_DIR}/lib/x86") + HINTS "${SDL2_DIR}/lib/x86" ${PC_SDL2_LIBRARY_DIRS}) find_library(SDL2_MAIN_LIBRARY "SDL2main" - PATHS "${SDL2_DIR}/lib/x86") + HINTS "${SDL2_DIR}/lib/x86" ${PC_SDL2_LIBRARY_DIRS}) endif() set(SDL2_LIBRARIES "${SDL2_MAIN_LIBRARY}" "${SDL2_LIBRARY}") @@ -78,6 +86,7 @@ if(SDL2_FOUND) # SDL2 imported target. add_library(SDL2::SDL2 UNKNOWN IMPORTED) set_target_properties(SDL2::SDL2 PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_SDL2_CFLAGS_OTHER}" INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" IMPORTED_LOCATION "${SDL2_LIBRARY}") diff --git a/cmake/FindSDL2_mixer.cmake b/cmake/FindSDL2_mixer.cmake index 446f1fb0..ce20e0b7 100644 --- a/cmake/FindSDL2_mixer.cmake +++ b/cmake/FindSDL2_mixer.cmake @@ -26,15 +26,23 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Currently works with the following generators: +# - Unix Makefiles +# - Ninja # - Visual Studio # Cache variable that allows you to point CMake at a directory containing # an extracted development library. set(SDL2_MIXER_DIR "${SDL2_MIXER_DIR}" CACHE PATH "Location of SDL2_mixer library directory") +# Use pkg-config to find library locations in *NIX environments. +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_SDL2_MIXER QUIET SDL2_mixer) +endif() + # Find the include directory. find_path(SDL2_MIXER_INCLUDE_DIR "SDL_mixer.h" - PATHS "${SDL2_MIXER_DIR}/include") + HINTS "${SDL2_MIXER_DIR}/include" ${PC_SDL2_MIXER_INCLUDE_DIRS}) # Find the version. Taken and modified from CMake's FindSDL.cmake. if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") @@ -56,10 +64,10 @@ endif() # Find the library. if(CMAKE_SIZEOF_VOID_P STREQUAL 8) find_library(SDL2_MIXER_LIBRARY "SDL2_mixer" - PATHS "${SDL2_MIXER_DIR}/lib/x64") + HINTS "${SDL2_MIXER_DIR}/lib/x64" ${PC_SDL2_MIXER_LIBRARY_DIRS}) else() - find_library(SDL2_MIXER_LIBRARY "SDL2" - PATHS "${SDL2_MIXER_DIR}/lib/x86") + find_library(SDL2_MIXER_LIBRARY "SDL2_mixer" + HINTS "${SDL2_MIXER_DIR}/lib/x86" ${PC_SDL2_MIXER_LIBRARY_DIRS}) endif() include(FindPackageHandleStandardArgs) @@ -73,6 +81,7 @@ if(SDL2_MIXER_FOUND) # Imported target. add_library(SDL2::mixer UNKNOWN IMPORTED) set_target_properties(SDL2::mixer PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_SDL2_MIXER_CFLAGS_OTHER}" INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIR}" INTERFACE_LINK_LIBRARIES SDL2::SDL2 IMPORTED_LOCATION "${SDL2_MIXER_LIBRARY}") diff --git a/cmake/FindSDL2_net.cmake b/cmake/FindSDL2_net.cmake index 87ab8338..5c743f2e 100644 --- a/cmake/FindSDL2_net.cmake +++ b/cmake/FindSDL2_net.cmake @@ -26,15 +26,23 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Currently works with the following generators: +# - Unix Makefiles +# - Ninja # - Visual Studio # Cache variable that allows you to point CMake at a directory containing # an extracted development library. set(SDL2_NET_DIR "${SDL2_NET_DIR}" CACHE PATH "Location of SDL2_net library directory") +# Use pkg-config to find library locations in *NIX environments. +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_SDL2_NET QUIET SDL2_net) +endif() + # Find the include directory. find_path(SDL2_NET_INCLUDE_DIR "SDL_net.h" - PATHS "${SDL2_NET_DIR}/include") + HINTS "${SDL2_NET_DIR}/include" ${PC_SDL2_NET_INCLUDE_DIRS}) # Find the version. Taken and modified from CMake's FindSDL.cmake. if(SDL2_NET_INCLUDE_DIR AND EXISTS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h") @@ -56,10 +64,10 @@ endif() # Find the library. if(CMAKE_SIZEOF_VOID_P STREQUAL 8) find_library(SDL2_NET_LIBRARY "SDL2_net" - PATHS "${SDL2_NET_DIR}/lib/x64") + HINTS "${SDL2_NET_DIR}/lib/x64" ${PC_SDL2_NET_LIBRARY_DIRS}) else() - find_library(SDL2_NET_LIBRARY "SDL2" - PATHS "${SDL2_NET_DIR}/lib/x86") + find_library(SDL2_NET_LIBRARY "SDL2_net" + HINTS "${SDL2_NET_DIR}/lib/x86" ${PC_SDL2_NET_LIBRARY_DIRS}) endif() include(FindPackageHandleStandardArgs) @@ -73,6 +81,7 @@ if(SDL2_NET_FOUND) # Imported target. add_library(SDL2::net UNKNOWN IMPORTED) set_target_properties(SDL2::net PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_SDL2_NET_CFLAGS_OTHER}" INTERFACE_INCLUDE_DIRECTORIES "${SDL2_NET_INCLUDE_DIR}" INTERFACE_LINK_LIBRARIES SDL2::SDL2 IMPORTED_LOCATION "${SDL2_NET_LIBRARY}") diff --git a/config.cmake.h b/config.cmake.h index ee30c96c..6a7818ce 100644 --- a/config.cmake.h +++ b/config.cmake.h @@ -1,3 +1,7 @@ #cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" +#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@" #cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" #cmakedefine PROGRAM_PREFIX "@PROGRAM_PREFIX@" + +#cmakedefine01 HAVE_DECL_STRCASECMP +#cmakedefine01 HAVE_DECL_STRNCASECMP diff --git a/midiproc/CMakeLists.txt b/midiproc/CMakeLists.txt index 1b6e27c5..d26d0613 100644 --- a/midiproc/CMakeLists.txt +++ b/midiproc/CMakeLists.txt @@ -1,4 +1,6 @@ -add_executable("${PROGRAM_PREFIX}midiproc" buffer.c buffer.h main.c proto.h) -target_include_directories("${PROGRAM_PREFIX}midiproc" - PRIVATE "../src/" "${CMAKE_CURRENT_BINARY_DIR}/../") -target_link_libraries("${PROGRAM_PREFIX}midiproc" SDL2::SDL2main SDL2::mixer) +if(WIN32) + add_executable("${PROGRAM_PREFIX}midiproc" buffer.c buffer.h main.c proto.h) + target_include_directories("${PROGRAM_PREFIX}midiproc" + PRIVATE "../src/" "${CMAKE_CURRENT_BINARY_DIR}/../") + target_link_libraries("${PROGRAM_PREFIX}midiproc" SDL2::SDL2main SDL2::mixer) +endif() From 59a66543a1013dcdd28fb893a921cd232165af7f Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Tue, 8 May 2018 20:43:07 -0400 Subject: [PATCH 08/24] Get resource file working Now, Chocolate Doom has an icon. Neat. --- CMakeLists.txt | 13 ++++++++++++- config.cmake.h => config.h.cin | 0 src/CMakeLists.txt | 11 ++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) rename config.cmake.h => config.h.cin (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1157044..14099ef6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,19 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") cmake_minimum_required(VERSION 3.7.2) project("Chocolate Doom" VERSION 3.0.0 LANGUAGES C) +# Autotools variables +set(top_srcdir ${CMAKE_CURRENT_SOURCE_DIR}) + # AC_INIT variables set(PACKAGE_NAME "${PROJECT_NAME}") set(PACKAGE_TARNAME "chocolate-doom") +set(PACKAGE_VERSION "${PROJECT_VERSION}") set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") +set(PACKAGE_BUGREPORT "chocolate-doom-dev-list@chocolate-doom.org") string(REGEX REPLACE " Doom$" "" PACKAGE_SHORTNAME "${PACKAGE_NAME}") +set(PACKAGE_COPYRIGHT "Copyright (C) 1993-2017") +set(PACKAGE_LICENSE "GNU General Public License, version 2") find_package(SDL2 2.0.1) find_package(SDL2_mixer 2.0.0) @@ -18,13 +25,17 @@ include(CheckFunctionExists) check_function_exists(strcasecmp HAVE_DECL_STRCASECMP) check_function_exists(strncasecmp HAVE_DECL_STRNCASECMP) +set(WINDOWS_RC_VERSION "${PROJECT_VERSION_MAJOR}, ${PROJECT_VERSION_MINOR}, ${PROJECT_VERSION_PATCH}, 0") + # Without a hyphen. This is used for the bash-completion scripts. string(TOLOWER "${PACKAGE_SHORTNAME}" PROGRAM_SPREFIX) # With a hyphen, used almost everywhere else. set(PROGRAM_PREFIX "${PROGRAM_SPREFIX}-") -configure_file(config.cmake.h config.h) +configure_file(config.h.cin config.h) + +configure_file(src/resource.rc.in src/resource.rc) foreach(SUBDIR textscreen midiproc opl pcsound src) add_subdirectory("${SUBDIR}") diff --git a/config.cmake.h b/config.h.cin similarity index 100% rename from config.cmake.h rename to config.h.cin diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83fe0eba..ac7530a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,8 +107,17 @@ set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES}) set(EXTRA_LIBS textscreen pcsound opl SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net) -add_executable("${PROGRAM_PREFIX}doom" ${SOURCE_FILES_WITH_DEH}) +if(WIN32) + add_executable("${PROGRAM_PREFIX}doom" ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") +else() + add_executable("${PROGRAM_PREFIX}doom" ${SOURCE_FILES_WITH_DEH}) +endif() target_include_directories("${PROGRAM_PREFIX}doom" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") target_link_libraries("${PROGRAM_PREFIX}doom" doom ${EXTRA_LIBS}) + +if(MSVC) + set_target_properties("${PROGRAM_PREFIX}doom" PROPERTIES + LINK_FLAGS "/MANIFEST:NO") +endif() From 07be64bbbfc345998d558afd0f84b1c9c430bd45 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Wed, 9 May 2018 20:03:20 -0400 Subject: [PATCH 09/24] Get Heretic, Hexen, Strife, and Setup compiling Something is messed up with Strife though, it crashes on boot. --- config.h.cin | 1 + src/CMakeLists.txt | 71 ++++++++ src/heretic/CMakeLists.txt | 57 +++++++ src/hexen/CMakeLists.txt | 58 +++++++ src/setup/CMakeLists.txt | 18 ++ src/strife/CMakeLists.txt | 75 +++++++++ win32/win_opendir.c | 336 +++++++++++++++++++++++++++++++++++++ win32/win_opendir.h | 73 ++++++++ 8 files changed, 689 insertions(+) create mode 100644 win32/win_opendir.c create mode 100644 win32/win_opendir.h diff --git a/config.h.cin b/config.h.cin index 6a7818ce..f2cbf21a 100644 --- a/config.h.cin +++ b/config.h.cin @@ -1,5 +1,6 @@ #cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" #cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@" +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" #cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" #cmakedefine PROGRAM_PREFIX "@PROGRAM_PREFIX@" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ac7530a0..8632da44 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -121,3 +121,74 @@ if(MSVC) set_target_properties("${PROGRAM_PREFIX}doom" PROPERTIES LINK_FLAGS "/MANIFEST:NO") endif() + +if(WIN32) + add_executable("${PROGRAM_PREFIX}heretic" ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") +else() + add_executable("${PROGRAM_PREFIX}heretic" ${SOURCE_FILES_WITH_DEH}) +endif() + +target_include_directories("${PROGRAM_PREFIX}heretic" + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries("${PROGRAM_PREFIX}heretic" heretic ${EXTRA_LIBS}) + +if(MSVC) + set_target_properties("${PROGRAM_PREFIX}heretic" PROPERTIES + LINK_FLAGS "/MANIFEST:NO") +endif() + +if(WIN32) + add_executable("${PROGRAM_PREFIX}hexen" ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") +else() + add_executable("${PROGRAM_PREFIX}hexen" ${SOURCE_FILES}) +endif() + +target_include_directories("${PROGRAM_PREFIX}hexen" + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries("${PROGRAM_PREFIX}hexen" hexen ${EXTRA_LIBS}) + +if(MSVC) + set_target_properties("${PROGRAM_PREFIX}hexen" PROPERTIES + LINK_FLAGS "/MANIFEST:NO") +endif() + +if(WIN32) + add_executable("${PROGRAM_PREFIX}strife" ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") +else() + add_executable("${PROGRAM_PREFIX}strife" ${SOURCE_FILES_WITH_DEH}) +endif() + +target_include_directories("${PROGRAM_PREFIX}strife" + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries("${PROGRAM_PREFIX}strife" strife ${EXTRA_LIBS}) + +if(MSVC) + set_target_properties("${PROGRAM_PREFIX}strife" PROPERTIES + LINK_FLAGS "/MANIFEST:NO") +endif() + +# Source files needed for chocolate-setup: + +set(SETUP_FILES + deh_str.c deh_str.h + d_mode.c d_mode.h + d_iwad.c d_iwad.h + i_timer.c i_timer.h + m_config.c m_config.h + m_controls.c m_controls.h + net_io.c net_io.h + net_packet.c net_packet.h + net_sdl.c net_sdl.h + net_query.c net_query.h + net_structrw.c net_structrw.h + z_native.c z_zone.h) + +#if(WIN32) + #add_executable("${PROGRAM_PREFIX}setup" ${SETUP_FILES} ${COMMON_SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/setup-res.rc") +#else() + add_executable("${PROGRAM_PREFIX}setup" ${SETUP_FILES} ${COMMON_SOURCE_FILES}) +#endif() + +target_include_directories("${PROGRAM_PREFIX}setup" + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries("${PROGRAM_PREFIX}setup" setup textscreen SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net) diff --git a/src/heretic/CMakeLists.txt b/src/heretic/CMakeLists.txt index e69de29b..9f12bde0 100644 --- a/src/heretic/CMakeLists.txt +++ b/src/heretic/CMakeLists.txt @@ -0,0 +1,57 @@ +add_library(heretic STATIC + am_data.h + am_map.c am_map.h + ct_chat.c ct_chat.h + deh_ammo.c + deh_frame.c + deh_htext.c + deh_htic.c deh_htic.h + deh_sound.c + deh_thing.c + deh_weapon.c + d_main.c + d_net.c + doomdata.h + doomdef.h + dstrings.h + f_finale.c + g_game.c + info.c info.h + in_lude.c + m_random.c m_random.h + mn_menu.c + p_action.h + p_ceilng.c + p_doors.c + p_enemy.c + p_floor.c + p_inter.c + p_lights.c + p_local.h + p_map.c + p_maputl.c + p_mobj.c + p_plats.c + p_pspr.c + p_saveg.c + p_setup.c + p_sight.c + p_spec.c p_spec.h + p_switch.c + p_telept.c + p_tick.c + p_user.c + r_bsp.c + r_data.c + r_draw.c + r_local.h + r_main.c + r_plane.c + r_segs.c + r_things.c + sb_bar.c + sounds.c sounds.h + s_sound.c s_sound.h) + +target_include_directories(heretic PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../") +target_link_libraries(heretic textscreen SDL2::SDL2 SDL2::mixer SDL2::net) diff --git a/src/hexen/CMakeLists.txt b/src/hexen/CMakeLists.txt index e69de29b..6b4beed2 100644 --- a/src/hexen/CMakeLists.txt +++ b/src/hexen/CMakeLists.txt @@ -0,0 +1,58 @@ +add_library(hexen STATIC + a_action.c + am_data.h + am_map.c am_map.h + ct_chat.c + ct_chat.h + d_net.c + f_finale.c + g_game.c + h2def.h + h2_main.c + info.c info.h + in_lude.c + m_random.c m_random.h + mn_menu.c + p_acs.c + p_anim.c + p_ceilng.c + p_doors.c + p_enemy.c + p_floor.c + p_inter.c + p_lights.c + p_local.h + p_map.c + p_maputl.c + p_mobj.c + po_man.c + p_plats.c + p_pspr.c + p_setup.c + p_sight.c + p_spec.c p_spec.h + p_switch.c + p_telept.c + p_things.c + p_tick.c + p_user.c + r_bsp.c + r_data.c + r_draw.c + r_local.h + r_main.c + r_plane.c + r_segs.c + r_things.c + s_sound.c s_sound.h + sb_bar.c + sc_man.c + sn_sonix.c + sounds.c sounds.h + st_start.c st_start.h + sv_save.c + textdefs.h + xddefs.h) + +target_include_directories(hexen PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../") +target_link_libraries(hexen SDL2::SDL2 SDL2::mixer SDL2::net) diff --git a/src/setup/CMakeLists.txt b/src/setup/CMakeLists.txt index e69de29b..4c27a07c 100644 --- a/src/setup/CMakeLists.txt +++ b/src/setup/CMakeLists.txt @@ -0,0 +1,18 @@ +add_library(setup STATIC + compatibility.c compatibility.h + display.c display.h + joystick.c joystick.h + keyboard.c keyboard.h + mainmenu.c + mode.c mode.h + mouse.c mouse.h + multiplayer.c multiplayer.h + sound.c sound.h + execute.c execute.h + txt_joyaxis.c txt_joyaxis.h + txt_joybinput.c txt_joybinput.h + txt_keyinput.c txt_keyinput.h + txt_mouseinput.c txt_mouseinput.h) + +target_include_directories(setup PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../") +target_link_libraries(setup textscreen SDL2::SDL2 SDL2::mixer) diff --git a/src/strife/CMakeLists.txt b/src/strife/CMakeLists.txt index e69de29b..3e5b9502 100644 --- a/src/strife/CMakeLists.txt +++ b/src/strife/CMakeLists.txt @@ -0,0 +1,75 @@ +set(STRIFE_SOURCES + am_map.c am_map.h + deh_ammo.c + deh_cheat.c + deh_strife.c + deh_frame.c + deh_misc.c deh_misc.h + deh_ptr.c + deh_sound.c + deh_thing.c + deh_weapon.c + d_englsh.h + d_items.c d_items.h + d_main.c d_main.h + d_net.c + doomdata.h + doomdef.c doomdef.h + doomstat.c doomstat.h + d_player.h + dstrings.c dstrings.h + d_textur.h + d_think.h + f_finale.c f_finale.h + f_wipe.c f_wipe.h + g_game.c g_game.h + hu_lib.c hu_lib.h + hu_stuff.c hu_stuff.h + info.c info.h + m_menu.c m_menu.h + m_random.c m_random.h + m_saves.c m_saves.h + p_ceilng.c + p_dialog.c p_dialog.h + p_doors.c + p_enemy.c + p_floor.c + p_inter.c p_inter.h + p_lights.c + p_local.h + p_map.c + p_maputl.c + p_mobj.c p_mobj.h + p_plats.c + p_pspr.c p_pspr.h + p_saveg.c p_saveg.h + p_setup.c p_setup.h + p_sight.c + p_spec.c p_spec.h + p_switch.c + p_telept.c + p_tick.c p_tick.h + p_user.c + r_bsp.c r_bsp.h + r_data.c r_data.h + r_defs.h + r_draw.c r_draw.h + r_local.h + r_main.c r_main.h + r_plane.c r_plane.h + r_segs.c r_segs.h + r_sky.c r_sky.h + r_state.h + r_things.c r_things.h + s_sound.c s_sound.h + sounds.c sounds.h + st_lib.c st_lib.h + st_stuff.c st_stuff.h + wi_stuff.c wi_stuff.h) +if(MSVC) + list(APPEND STRIFE_SOURCES "../../win32/win_opendir.c" "../../win32/win_opendir.h") +endif() +add_library(strife STATIC ${STRIFE_SOURCES}) + +target_include_directories(strife PRIVATE "../" "../../win32/" "${CMAKE_CURRENT_BINARY_DIR}/../../") +target_link_libraries(strife textscreen SDL2::SDL2 SDL2::mixer SDL2::net) diff --git a/win32/win_opendir.c b/win32/win_opendir.c new file mode 100644 index 00000000..b2f67805 --- /dev/null +++ b/win32/win_opendir.c @@ -0,0 +1,336 @@ +// +// 03/10/2006 James Haley +// +// For this module only: +// This code is public domain. No change sufficient enough to constitute a +// significant or original work has been made, and thus it remains as such. +// +// +// DESCRIPTION: +// +// Implementation of POSIX opendir for Visual C++. +// Derived from the MinGW C Library Extensions Source (released to the +// public domain). As with other Win32 modules, don't include most DOOM +// headers into this or conflicts will occur. +// +// Original Header: +// +// * dirent.c +// * This file has no copyright assigned and is placed in the Public Domain. +// * This file is a part of the mingw-runtime package. +// * No warranty is given; refer to the file DISCLAIMER within the package. +// * +// * Derived from DIRLIB.C by Matt J. Weinstein +// * This note appears in the DIRLIB.H +// * DIRLIB.H by M. J. Weinstein Released to public domain 1-Jan-89 +// * +// * Updated by Jeremy Bettis +// * Significantly revised and rewinddir, seekdir and telldir added by Colin +// * Peters +// + +#ifndef _MSC_VER +#error i_opndir.c is for Microsoft Visual C++ only +#endif + +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#include /* for GetFileAttributes */ + +#include +#define SUFFIX _T("*") +#define SLASH _T("\\") + +#include "win_opendir.h" + +// +// opendir +// +// Returns a pointer to a DIR structure appropriately filled in to begin +// searching a directory. +// +DIR *opendir(const _TCHAR *szPath) +{ + DIR *nd; + unsigned int rc; + _TCHAR szFullPath[MAX_PATH]; + + errno = 0; + + if(!szPath) + { + errno = EFAULT; + return (DIR *)0; + } + + if(szPath[0] == _T('\0')) + { + errno = ENOTDIR; + return (DIR *)0; + } + + /* Attempt to determine if the given path really is a directory. */ + rc = GetFileAttributes(szPath); + if(rc == (unsigned int)-1) + { + /* call GetLastError for more error info */ + errno = ENOENT; + return (DIR *)0; + } + if(!(rc & FILE_ATTRIBUTE_DIRECTORY)) + { + /* Error, entry exists but not a directory. */ + errno = ENOTDIR; + return (DIR *)0; + } + + /* Make an absolute pathname. */ + _tfullpath(szFullPath, szPath, MAX_PATH); + + /* Allocate enough space to store DIR structure and the complete + * directory path given. */ + nd = (DIR *)(malloc(sizeof(DIR) + (_tcslen(szFullPath) + + _tcslen(SLASH) + + _tcslen(SUFFIX) + 1) + * sizeof(_TCHAR))); + + if(!nd) + { + /* Error, out of memory. */ + errno = ENOMEM; + return (DIR *)0; + } + + /* Create the search expression. */ + _tcscpy(nd->dd_name, szFullPath); + + /* Add on a slash if the path does not end with one. */ + if(nd->dd_name[0] != _T('\0') + && _tcsrchr(nd->dd_name, _T('/')) != nd->dd_name + + _tcslen(nd->dd_name) - 1 + && _tcsrchr(nd->dd_name, _T('\\')) != nd->dd_name + + _tcslen(nd->dd_name) - 1) + { + _tcscat(nd->dd_name, SLASH); + } + + /* Add on the search pattern */ + _tcscat(nd->dd_name, SUFFIX); + + /* Initialize handle to -1 so that a premature closedir doesn't try + * to call _findclose on it. */ + nd->dd_handle = -1; + + /* Initialize the status. */ + nd->dd_stat = 0; + + /* Initialize the dirent structure. ino and reclen are invalid under + * Win32, and name simply points at the appropriate part of the + * findfirst_t structure. */ + nd->dd_dir.d_ino = 0; + nd->dd_dir.d_reclen = 0; + nd->dd_dir.d_namlen = 0; + memset(nd->dd_dir.d_name, 0, FILENAME_MAX); + + return nd; +} + +// +// readdir +// +// Return a pointer to a dirent structure filled with the information on the +// next entry in the directory. +// +struct dirent *readdir(DIR *dirp) +{ + errno = 0; + + /* Check for valid DIR struct. */ + if(!dirp) + { + errno = EFAULT; + return (struct dirent *)0; + } + + if (dirp->dd_stat < 0) + { + /* We have already returned all files in the directory + * (or the structure has an invalid dd_stat). */ + return (struct dirent *)0; + } + else if (dirp->dd_stat == 0) + { + /* We haven't started the search yet. */ + /* Start the search */ + dirp->dd_handle = _tfindfirst(dirp->dd_name, &(dirp->dd_dta)); + + if(dirp->dd_handle == -1) + { + /* Whoops! Seems there are no files in that + * directory. */ + dirp->dd_stat = -1; + } + else + { + dirp->dd_stat = 1; + } + } + else + { + /* Get the next search entry. */ + if(_tfindnext(dirp->dd_handle, &(dirp->dd_dta))) + { + /* We are off the end or otherwise error. + _findnext sets errno to ENOENT if no more file + Undo this. */ + DWORD winerr = GetLastError(); + if(winerr == ERROR_NO_MORE_FILES) + errno = 0; + _findclose(dirp->dd_handle); + dirp->dd_handle = -1; + dirp->dd_stat = -1; + } + else + { + /* Update the status to indicate the correct + * number. */ + dirp->dd_stat++; + } + } + + if (dirp->dd_stat > 0) + { + /* Successfully got an entry. Everything about the file is + * already appropriately filled in except the length of the + * file name. */ + dirp->dd_dir.d_namlen = _tcslen(dirp->dd_dta.name); + _tcscpy(dirp->dd_dir.d_name, dirp->dd_dta.name); + return &dirp->dd_dir; + } + + return (struct dirent *)0; +} + + +// +// closedir +// +// Frees up resources allocated by opendir. +// +int closedir(DIR *dirp) +{ + int rc; + + errno = 0; + rc = 0; + + if(!dirp) + { + errno = EFAULT; + return -1; + } + + if(dirp->dd_handle != -1) + { + rc = _findclose(dirp->dd_handle); + } + + /* Delete the dir structure. */ + free(dirp); + + return rc; +} + +// +// rewinddir +// +// Return to the beginning of the directory "stream". We simply call findclose +// and then reset things like an opendir. +// +void rewinddir(DIR * dirp) +{ + errno = 0; + + if(!dirp) + { + errno = EFAULT; + return; + } + + if(dirp->dd_handle != -1) + { + _findclose(dirp->dd_handle); + } + + dirp->dd_handle = -1; + dirp->dd_stat = 0; +} + +// +// telldir +// +// Returns the "position" in the "directory stream" which can be used with +// seekdir to go back to an old entry. We simply return the value in stat. +// +long telldir(DIR *dirp) +{ + errno = 0; + + if(!dirp) + { + errno = EFAULT; + return -1; + } + return dirp->dd_stat; +} + +// +// seekdir +// +// Seek to an entry previously returned by telldir. We rewind the directory +// and call readdir repeatedly until either dd_stat is the position number +// or -1 (off the end). This is not perfect, in that the directory may +// have changed while we weren't looking. But that is probably the case with +// any such system. +// +void seekdir(DIR *dirp, long lPos) +{ + errno = 0; + + if(!dirp) + { + errno = EFAULT; + return; + } + + if(lPos < -1) + { + /* Seeking to an invalid position. */ + errno = EINVAL; + return; + } + else if(lPos == -1) + { + /* Seek past end. */ + if(dirp->dd_handle != -1) + { + _findclose(dirp->dd_handle); + } + dirp->dd_handle = -1; + dirp->dd_stat = -1; + } + else + { + /* Rewind and read forward to the appropriate index. */ + rewinddir(dirp); + + while((dirp->dd_stat < lPos) && readdir(dirp)) + ; /* do-nothing loop */ + } +} + +// EOF + diff --git a/win32/win_opendir.h b/win32/win_opendir.h new file mode 100644 index 00000000..3fe0f793 --- /dev/null +++ b/win32/win_opendir.h @@ -0,0 +1,73 @@ +// +// 03/10/2006 James Haley +// +// For this module only: +// This code is public domain. No change sufficient enough to constitute a +// significant or original work has been made, and thus it remains as such. +// +// +// DESCRIPTION: +// +// Implementation of POSIX opendir for Visual C++. +// Derived from the MinGW C Library Extensions Source (released to the +// public domain). +// + +#ifndef I_OPNDIR_H__ +#define I_OPNDIR_H__ + +#include + +#ifndef FILENAME_MAX +#define FILENAME_MAX 260 +#endif + +struct dirent +{ + long d_ino; /* Always zero. */ + unsigned short d_reclen; /* Always zero. */ + unsigned short d_namlen; /* Length of name in d_name. */ + char d_name[FILENAME_MAX]; /* File name. */ +}; + +/* + * This is an internal data structure. Good programmers will not use it + * except as an argument to one of the functions below. + * dd_stat field is now int (was short in older versions). + */ +typedef struct +{ + /* disk transfer area for this dir */ + struct _finddata_t dd_dta; + + /* dirent struct to return from dir (NOTE: this makes this thread + * safe as long as only one thread uses a particular DIR struct at + * a time) */ + struct dirent dd_dir; + + /* _findnext handle */ + long dd_handle; + + /* + * Status of search: + * 0 = not started yet (next entry to read is first entry) + * -1 = off the end + * positive = 0 based index of next entry + */ + int dd_stat; + + /* given path for dir with search pattern (struct is extended) */ + char dd_name[1]; +} DIR; + +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +int closedir(DIR *); +void rewinddir(DIR *); +long telldir(DIR *); +void seekdir(DIR *, long); + +#endif + +// EOF + From a10578ede677e72c7832775f5020d855dccc01ce Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Wed, 9 May 2018 20:07:59 -0400 Subject: [PATCH 10/24] Strife now boots The problem was the opendir implementation. The handle that is passed around to _findnext and friends is supposed to be a intptr_t, but was only a long instead. I suspect the problem only showed up on 64-bit builds beforehand. --- win32/win_opendir.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/win_opendir.h b/win32/win_opendir.h index 3fe0f793..c1844e11 100644 --- a/win32/win_opendir.h +++ b/win32/win_opendir.h @@ -46,7 +46,7 @@ typedef struct struct dirent dd_dir; /* _findnext handle */ - long dd_handle; + intptr_t dd_handle; /* * Status of search: From bd8f0e81e774c8241b5bd985fe5563b302834db9 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Mon, 21 May 2018 18:29:14 -0400 Subject: [PATCH 11/24] Fix setup executable rc and manifest files --- CMakeLists.txt | 3 +++ src/CMakeLists.txt | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14099ef6..abb073f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ project("Chocolate Doom" VERSION 3.0.0 LANGUAGES C) # Autotools variables set(top_srcdir ${CMAKE_CURRENT_SOURCE_DIR}) +set(top_builddir ${CMAKE_CURRENT_BINARY_DIR}) # AC_INIT variables set(PACKAGE_NAME "${PROJECT_NAME}") @@ -36,6 +37,8 @@ set(PROGRAM_PREFIX "${PROGRAM_SPREFIX}-") configure_file(config.h.cin config.h) configure_file(src/resource.rc.in src/resource.rc) +configure_file(src/setup-res.rc.in src/setup-res.rc) +configure_file(src/setup/setup-manifest.xml.in src/setup/setup-manifest.xml) foreach(SUBDIR textscreen midiproc opl pcsound src) add_subdirectory("${SUBDIR}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8632da44..2615893b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -183,12 +183,17 @@ set(SETUP_FILES net_structrw.c net_structrw.h z_native.c z_zone.h) -#if(WIN32) - #add_executable("${PROGRAM_PREFIX}setup" ${SETUP_FILES} ${COMMON_SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/setup-res.rc") -#else() +if(WIN32) + add_executable("${PROGRAM_PREFIX}setup" ${SETUP_FILES} ${COMMON_SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/setup-res.rc") +else() add_executable("${PROGRAM_PREFIX}setup" ${SETUP_FILES} ${COMMON_SOURCE_FILES}) -#endif() +endif() target_include_directories("${PROGRAM_PREFIX}setup" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") target_link_libraries("${PROGRAM_PREFIX}setup" setup textscreen SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net) + +if(MSVC) + set_target_properties("${PROGRAM_PREFIX}setup" PROPERTIES + LINK_FLAGS "/MANIFEST:NO") +endif() From 5f043db7d5e1846190096e9af3f289b60b0ba1b2 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Tue, 22 May 2018 20:27:15 -0400 Subject: [PATCH 12/24] Global fixes for MSVC warning spam --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index abb073f4..fa1f6c32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,13 @@ string(REGEX REPLACE " Doom$" "" PACKAGE_SHORTNAME "${PACKAGE_NAME}") set(PACKAGE_COPYRIGHT "Copyright (C) 1993-2017") set(PACKAGE_LICENSE "GNU General Public License, version 2") +# Any settings that should apply to all targets in this directory and all +# subdirectories should go here. Use judiciously. +if(MSVC) + add_definitions("/D_CRT_SECURE_NO_WARNINGS" "/D_CRT_SECURE_NO_DEPRECATE" + "/D_CRT_NONSTDC_NO_DEPRECATE") +endif() + find_package(SDL2 2.0.1) find_package(SDL2_mixer 2.0.0) find_package(SDL2_net 2.0.0) From d6cb093e4cac91908b6aa3f9944104e0220720c9 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Tue, 22 May 2018 20:42:44 -0400 Subject: [PATCH 13/24] Apply WIN32 to executables This changes the binaries to use the WINDOWS subsystem. --- midiproc/CMakeLists.txt | 2 +- src/CMakeLists.txt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/midiproc/CMakeLists.txt b/midiproc/CMakeLists.txt index d26d0613..144e9248 100644 --- a/midiproc/CMakeLists.txt +++ b/midiproc/CMakeLists.txt @@ -1,5 +1,5 @@ if(WIN32) - add_executable("${PROGRAM_PREFIX}midiproc" buffer.c buffer.h main.c proto.h) + add_executable("${PROGRAM_PREFIX}midiproc" WIN32 buffer.c buffer.h main.c proto.h) target_include_directories("${PROGRAM_PREFIX}midiproc" PRIVATE "../src/" "${CMAKE_CURRENT_BINARY_DIR}/../") target_link_libraries("${PROGRAM_PREFIX}midiproc" SDL2::SDL2main SDL2::mixer) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2615893b..e5d6bfe1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,7 +26,7 @@ set(DEDSERV_FILES net_structrw.c net_structrw.h z_native.c z_zone.h) -add_executable("${PROGRAM_PREFIX}server" ${COMMON_SOURCE_FILES} ${DEDSERV_FILES}) +add_executable("${PROGRAM_PREFIX}server" WIN32 ${COMMON_SOURCE_FILES} ${DEDSERV_FILES}) target_include_directories("${PROGRAM_PREFIX}server" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") target_link_libraries("${PROGRAM_PREFIX}server" SDL2::SDL2main SDL2::net) @@ -108,7 +108,7 @@ set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES}) set(EXTRA_LIBS textscreen pcsound opl SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net) if(WIN32) - add_executable("${PROGRAM_PREFIX}doom" ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") + add_executable("${PROGRAM_PREFIX}doom" WIN32 ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") else() add_executable("${PROGRAM_PREFIX}doom" ${SOURCE_FILES_WITH_DEH}) endif() @@ -123,7 +123,7 @@ if(MSVC) endif() if(WIN32) - add_executable("${PROGRAM_PREFIX}heretic" ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") + add_executable("${PROGRAM_PREFIX}heretic" WIN32 ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") else() add_executable("${PROGRAM_PREFIX}heretic" ${SOURCE_FILES_WITH_DEH}) endif() @@ -138,7 +138,7 @@ if(MSVC) endif() if(WIN32) - add_executable("${PROGRAM_PREFIX}hexen" ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") + add_executable("${PROGRAM_PREFIX}hexen" WIN32 ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") else() add_executable("${PROGRAM_PREFIX}hexen" ${SOURCE_FILES}) endif() @@ -153,7 +153,7 @@ if(MSVC) endif() if(WIN32) - add_executable("${PROGRAM_PREFIX}strife" ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") + add_executable("${PROGRAM_PREFIX}strife" WIN32 ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") else() add_executable("${PROGRAM_PREFIX}strife" ${SOURCE_FILES_WITH_DEH}) endif() @@ -184,7 +184,7 @@ set(SETUP_FILES z_native.c z_zone.h) if(WIN32) - add_executable("${PROGRAM_PREFIX}setup" ${SETUP_FILES} ${COMMON_SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/setup-res.rc") + add_executable("${PROGRAM_PREFIX}setup" WIN32 ${SETUP_FILES} ${COMMON_SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/setup-res.rc") else() add_executable("${PROGRAM_PREFIX}setup" ${SETUP_FILES} ${COMMON_SOURCE_FILES}) endif() From 42b80fe839535f4f477ff91e300bf06fc7cdc711 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Tue, 22 May 2018 21:05:09 -0400 Subject: [PATCH 14/24] Add midiread and mus2mid targets --- src/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5d6bfe1..452d8321 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -197,3 +197,13 @@ if(MSVC) set_target_properties("${PROGRAM_PREFIX}setup" PROPERTIES LINK_FLAGS "/MANIFEST:NO") endif() + +add_executable(midiread midifile.c z_native.c i_system.c m_argv.c m_misc.c) +target_compile_definitions(midiread PRIVATE "-DTEST") +target_include_directories(midiread PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries(midiread PRIVATE SDL2::SDL2) + +add_executable(mus2mid mus2mid.c memio.c z_native.c i_system.c m_argv.c m_misc.c) +target_compile_definitions(mus2mid PRIVATE "-DSTANDALONE") +target_include_directories(mus2mid PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") +target_link_libraries(mus2mid PRIVATE SDL2::SDL2) From 2eb722d3a4053eadef3da207c45e644adf17baa8 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Sat, 26 May 2018 17:12:02 -0400 Subject: [PATCH 15/24] Link against libpng and libm Tested against Ubuntu 18.04. --- CMakeLists.txt | 8 ++++++++ config.h.cin | 1 + src/CMakeLists.txt | 3 +++ textscreen/CMakeLists.txt | 2 +- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa1f6c32..7f569d61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,14 @@ find_package(SDL2 2.0.1) find_package(SDL2_mixer 2.0.0) find_package(SDL2_net 2.0.0) +# Check for libpng. +find_package(PNG) +if(PNG_FOUND) + set(HAVE_LIBPNG TRUE) +endif() + +find_package(m) + include(CheckFunctionExists) check_function_exists(strcasecmp HAVE_DECL_STRCASECMP) check_function_exists(strncasecmp HAVE_DECL_STRNCASECMP) diff --git a/config.h.cin b/config.h.cin index f2cbf21a..4a3b8a15 100644 --- a/config.h.cin +++ b/config.h.cin @@ -4,5 +4,6 @@ #cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" #cmakedefine PROGRAM_PREFIX "@PROGRAM_PREFIX@" +#cmakedefine01 HAVE_LIBPNG #cmakedefine01 HAVE_DECL_STRCASECMP #cmakedefine01 HAVE_DECL_STRNCASECMP diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 452d8321..ca9fc502 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -106,6 +106,9 @@ set(SOURCE_FILES ${COMMON_SOURCE_FILES} ${GAME_SOURCE_FILES}) set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES}) set(EXTRA_LIBS textscreen pcsound opl SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net) +if(PNG_FOUND) + list(APPEND EXTRA_LIBS PNG::PNG) +endif() if(WIN32) add_executable("${PROGRAM_PREFIX}doom" WIN32 ${SOURCE_FILES_WITH_DEH} "${CMAKE_CURRENT_BINARY_DIR}/resource.rc") diff --git a/textscreen/CMakeLists.txt b/textscreen/CMakeLists.txt index bf9fa1fb..2a1802a6 100644 --- a/textscreen/CMakeLists.txt +++ b/textscreen/CMakeLists.txt @@ -25,4 +25,4 @@ add_library(textscreen target_include_directories(textscreen INTERFACE "." PRIVATE "../src/") -target_link_libraries(textscreen SDL2::SDL2) +target_link_libraries(textscreen m SDL2::SDL2) From 24e03872961c818e4de0c174772d4d4123bc6bde Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Sat, 26 May 2018 17:15:28 -0400 Subject: [PATCH 16/24] Whoops, forgot to add Findm.cmake --- cmake/Findm.cmake | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 cmake/Findm.cmake diff --git a/cmake/Findm.cmake b/cmake/Findm.cmake new file mode 100644 index 00000000..f7a1cfa5 --- /dev/null +++ b/cmake/Findm.cmake @@ -0,0 +1,36 @@ +# Findm.cmake +# +# Copyright (c) 2018, Alex Mayfield +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Finds libm, so we can link against it for math functions. If libm doesn't +# exist, linking against the m target will have no effect. + +find_library(M_LIBRARY m) + +add_library(m INTERFACE) +if(M_LIBRARY) + target_link_libraries(m INTERFACE "${M_LIBRARY}") +endif() From 3d315652c31b7858af29448b2f796ee2363a66b3 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Sat, 26 May 2018 17:21:18 -0400 Subject: [PATCH 17/24] If libpng is missing, do not define HAVE_LIBPNG --- config.h.cin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.h.cin b/config.h.cin index 4a3b8a15..1c875bbe 100644 --- a/config.h.cin +++ b/config.h.cin @@ -4,6 +4,6 @@ #cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" #cmakedefine PROGRAM_PREFIX "@PROGRAM_PREFIX@" -#cmakedefine01 HAVE_LIBPNG +#cmakedefine HAVE_LIBPNG #cmakedefine01 HAVE_DECL_STRCASECMP #cmakedefine01 HAVE_DECL_STRNCASECMP From 8b8c8bf3d131445ae13cdfacdb7bb393561da0c4 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Sun, 27 May 2018 00:09:20 -0400 Subject: [PATCH 18/24] Fix PNG screenshot crash with MSVC malloc wasn't getting declared on MSVC, leading to calling an implicitly decleared function. I think those return int, which caused the return value to be truncated on x64 builds, leading to an access violation on write. --- src/v_video.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/v_video.c b/src/v_video.c index cabfba71..22e5602a 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -20,6 +20,7 @@ // #include +#include #include #include From dc054603a1f95f03ea9f6a7b79cda23032c5c2a6 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Thu, 31 May 2018 19:12:31 -0400 Subject: [PATCH 19/24] libsamplerate support Works on Linux, at least... --- CMakeLists.txt | 6 ++++ cmake/Findsamplerate.cmake | 71 ++++++++++++++++++++++++++++++++++++++ config.h.cin | 1 + src/CMakeLists.txt | 3 ++ 4 files changed, 81 insertions(+) create mode 100644 cmake/Findsamplerate.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f569d61..c304b011 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,12 @@ find_package(SDL2 2.0.1) find_package(SDL2_mixer 2.0.0) find_package(SDL2_net 2.0.0) +# Check for libsamplerate. +find_package(samplerate) +if(SAMPLERATE_FOUND) + set(HAVE_LIBSAMPLERATE TRUE) +endif() + # Check for libpng. find_package(PNG) if(PNG_FOUND) diff --git a/cmake/Findsamplerate.cmake b/cmake/Findsamplerate.cmake new file mode 100644 index 00000000..c7fab93a --- /dev/null +++ b/cmake/Findsamplerate.cmake @@ -0,0 +1,71 @@ +# Findsamplerate.cmake +# +# Copyright (c) 2018, Alex Mayfield +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Currently works with the following generators: +# - Unix Makefiles +# - Ninja +# - Visual Studio (TODO) + +# Cache variable that allows you to point CMake at a directory containing +# an extracted development library. +set(SAMPLERATE_DIR "${SAMPLERATE_DIR}" CACHE PATH "Location of samplerate library directory") + +# Use pkg-config to find library locations in *NIX environments. +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_SAMPLERATE QUIET samplerate) +endif() + +# Find the include directory. +find_path(SAMPLERATE_INCLUDE_DIR "samplerate.h" + HINTS ${PC_SAMPLERATE_INCLUDE_DIRS}) + +# Find the version. I don't know if there is a correct way to find this on +# Windows - the config.h in the tarball is wrong for 0.1.19. +if(PC_SAMPLERATE_VERSION) + set(SAMPLERATE_VERSION "${PC_SAMPLERATE_VERSION}") +endif() + +# Find the library. +find_library(SAMPLERATE_LIBRARY "samplerate" + HINTS ${PC_SAMPLERATE_LIBRARY_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(samplerate + FOUND_VAR SAMPLERATE_FOUND + REQUIRED_VARS SAMPLERATE_INCLUDE_DIR SAMPLERATE_LIBRARY + VERSION_VAR SAMPLERATE_VERSION +) + +if(SAMPLERATE_FOUND) + # Imported target. + add_library(samplerate::samplerate UNKNOWN IMPORTED) + set_target_properties(samplerate::samplerate PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_SAMPLERATE_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${SAMPLERATE_INCLUDE_DIR}" + IMPORTED_LOCATION "${SAMPLERATE_LIBRARY}") +endif() diff --git a/config.h.cin b/config.h.cin index 1c875bbe..4a67927e 100644 --- a/config.h.cin +++ b/config.h.cin @@ -4,6 +4,7 @@ #cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" #cmakedefine PROGRAM_PREFIX "@PROGRAM_PREFIX@" +#cmakedefine HAVE_LIBSAMPLERATE #cmakedefine HAVE_LIBPNG #cmakedefine01 HAVE_DECL_STRCASECMP #cmakedefine01 HAVE_DECL_STRNCASECMP diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca9fc502..00ed3d53 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -106,6 +106,9 @@ set(SOURCE_FILES ${COMMON_SOURCE_FILES} ${GAME_SOURCE_FILES}) set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES}) set(EXTRA_LIBS textscreen pcsound opl SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net) +if(SAMPLERATE_FOUND) + list(APPEND EXTRA_LIBS samplerate::samplerate) +endif() if(PNG_FOUND) list(APPEND EXTRA_LIBS PNG::PNG) endif() From f8ffe42a61cc53719bd36d58d309d495ad3f323b Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Thu, 31 May 2018 19:14:57 -0400 Subject: [PATCH 20/24] Add GCC warnings from autotools --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c304b011..cd026453 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,9 @@ set(PACKAGE_LICENSE "GNU General Public License, version 2") if(MSVC) add_definitions("/D_CRT_SECURE_NO_WARNINGS" "/D_CRT_SECURE_NO_DEPRECATE" "/D_CRT_NONSTDC_NO_DEPRECATE") +else() + add_compile_options("-Wall" "-Wdeclaration-after-statement" + "-Wredundant-decls") endif() find_package(SDL2 2.0.1) From cc24dc35abad25ee43805f9a19c57d5f527ac7a0 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Thu, 31 May 2018 22:34:10 -0400 Subject: [PATCH 21/24] Works in Visual Studio too --- cmake/Findsamplerate.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Findsamplerate.cmake b/cmake/Findsamplerate.cmake index c7fab93a..18c7b483 100644 --- a/cmake/Findsamplerate.cmake +++ b/cmake/Findsamplerate.cmake @@ -28,7 +28,7 @@ # Currently works with the following generators: # - Unix Makefiles # - Ninja -# - Visual Studio (TODO) +# - Visual Studio # Cache variable that allows you to point CMake at a directory containing # an extracted development library. From 9d815c5d43b8bfddab5900cd24abb9c11ddbcb90 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Fri, 1 Jun 2018 18:12:53 -0400 Subject: [PATCH 22/24] Remove unused samplerate directory cache variable The variable isn't referenced anywhere else in the finder script. --- cmake/Findsamplerate.cmake | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cmake/Findsamplerate.cmake b/cmake/Findsamplerate.cmake index 18c7b483..02530d0b 100644 --- a/cmake/Findsamplerate.cmake +++ b/cmake/Findsamplerate.cmake @@ -30,10 +30,6 @@ # - Ninja # - Visual Studio -# Cache variable that allows you to point CMake at a directory containing -# an extracted development library. -set(SAMPLERATE_DIR "${SAMPLERATE_DIR}" CACHE PATH "Location of samplerate library directory") - # Use pkg-config to find library locations in *NIX environments. find_package(PkgConfig QUIET) if(PKG_CONFIG_FOUND) From 360da28234c5aef0690a115fcf625e06d95470d2 Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Sun, 3 Jun 2018 10:50:32 -0400 Subject: [PATCH 23/24] Fix strcasecmp detection Our detection must include strings.h. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd026453..714b8f3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,9 +46,9 @@ endif() find_package(m) -include(CheckFunctionExists) -check_function_exists(strcasecmp HAVE_DECL_STRCASECMP) -check_function_exists(strncasecmp HAVE_DECL_STRNCASECMP) +include(CheckSymbolExists) +check_symbol_exists(strcasecmp "strings.h" HAVE_DECL_STRCASECMP) +check_symbol_exists(strncasecmp "strings.h" HAVE_DECL_STRNCASECMP) set(WINDOWS_RC_VERSION "${PROJECT_VERSION_MAJOR}, ${PROJECT_VERSION_MINOR}, ${PROJECT_VERSION_PATCH}, 0") From d0497ad2cd385bbfe741542052cef91339d1dd3d Mon Sep 17 00:00:00 2001 From: Alex Mayfield Date: Mon, 4 Jun 2018 17:57:56 -0400 Subject: [PATCH 24/24] Address pull request comments --- CMakeLists.txt | 5 +++-- config.h.cin => cmake/config.h.cin | 0 2 files changed, 3 insertions(+), 2 deletions(-) rename config.h.cin => cmake/config.h.cin (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 714b8f3b..58c200b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,8 @@ include(CheckSymbolExists) check_symbol_exists(strcasecmp "strings.h" HAVE_DECL_STRCASECMP) check_symbol_exists(strncasecmp "strings.h" HAVE_DECL_STRNCASECMP) -set(WINDOWS_RC_VERSION "${PROJECT_VERSION_MAJOR}, ${PROJECT_VERSION_MINOR}, ${PROJECT_VERSION_PATCH}, 0") +string(CONCAT WINDOWS_RC_VERSION "${PROJECT_VERSION_MAJOR}, " + "${PROJECT_VERSION_MINOR}, ${PROJECT_VERSION_PATCH}, 0") # Without a hyphen. This is used for the bash-completion scripts. string(TOLOWER "${PACKAGE_SHORTNAME}" PROGRAM_SPREFIX) @@ -58,7 +59,7 @@ string(TOLOWER "${PACKAGE_SHORTNAME}" PROGRAM_SPREFIX) # With a hyphen, used almost everywhere else. set(PROGRAM_PREFIX "${PROGRAM_SPREFIX}-") -configure_file(config.h.cin config.h) +configure_file(cmake/config.h.cin config.h) configure_file(src/resource.rc.in src/resource.rc) configure_file(src/setup-res.rc.in src/setup-res.rc) diff --git a/config.h.cin b/cmake/config.h.cin similarity index 100% rename from config.h.cin rename to cmake/config.h.cin