From 896da81bd6270d8ce02c3eafa92aef52c36c840d Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 27 May 2023 13:45:45 -0600 Subject: [PATCH] bsputil: refactor into a static lib --- bsputil/CMakeLists.txt | 8 ++++++-- bsputil/bsputil.cc | 4 ++-- bsputil/main.cc | 25 +++++++++++++++++++++++++ include/bsputil/bsputil.hh | 25 +++++++++++++++++++++++++ tests/CMakeLists.txt | 2 +- 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 bsputil/main.cc create mode 100644 include/bsputil/bsputil.hh diff --git a/bsputil/CMakeLists.txt b/bsputil/CMakeLists.txt index a799e33d..7f8adde2 100644 --- a/bsputil/CMakeLists.txt +++ b/bsputil/CMakeLists.txt @@ -1,9 +1,13 @@ set(BSPUTIL_SOURCES bsputil.cc + ../include/bsputil/bsputil.hh ) -add_executable(bsputil ${BSPUTIL_SOURCES}) -target_link_libraries(bsputil common TBB::tbb TBB::tbbmalloc fmt::fmt) +add_library(libbsputil STATIC ${BSPUTIL_SOURCES}) +target_link_libraries(libbsputil common TBB::tbb TBB::tbbmalloc fmt::fmt) + +add_executable(bsputil main.cc) +target_link_libraries(bsputil libbsputil) # HACK: copy .dll dependencies add_custom_command(TARGET bsputil POST_BUILD diff --git a/bsputil/bsputil.cc b/bsputil/bsputil.cc index ff7f2890..abdcd3f7 100644 --- a/bsputil/bsputil.cc +++ b/bsputil/bsputil.cc @@ -61,7 +61,7 @@ struct lumpinfo_t auto stream_data() { return std::tie(filepos, disksize, size, type, compression, pad1, pad2, name); } }; -static void ExportWad(std::ofstream &wadfile, mbsp_t *bsp) +void ExportWad(std::ofstream &wadfile, const mbsp_t *bsp) { int filepos, numvalid; const auto &texdata = bsp->dtex; @@ -564,7 +564,7 @@ map_file_t LoadMapOrEntFile(const fs::path &source) return map; } -int main(int argc, char **argv) +int bsputil_main(int argc, char **argv) { logging::preinitialize(); diff --git a/bsputil/main.cc b/bsputil/main.cc new file mode 100644 index 00000000..2a49b51c --- /dev/null +++ b/bsputil/main.cc @@ -0,0 +1,25 @@ +/* Copyright (C) 1996-1997 Id Software, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + See file, 'COPYING', for details. +*/ + +#include + +int main(int argc, char **argv) +{ + return bsputil_main(argc, argv); +} diff --git a/include/bsputil/bsputil.hh b/include/bsputil/bsputil.hh new file mode 100644 index 00000000..e991a924 --- /dev/null +++ b/include/bsputil/bsputil.hh @@ -0,0 +1,25 @@ +/* Copyright (C) 1996-1997 Id Software, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + See file, 'COPYING', for details. +*/ + +#include + +struct mbsp_t; + +void ExportWad(std::ofstream &wadfile, const mbsp_t *bsp); +int bsputil_main(int argc, char **argv); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b85d4546..720257f4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,7 +29,7 @@ if (NOT EMBREE_TBB_DLL STREQUAL EMBREE_TBB_DLL-NOTFOUND) message(STATUS "Found embree EMBREE_TBB_DLL: ${EMBREE_TBB_DLL}") endif() -target_link_libraries(tests libqbsp liblight libvis common TBB::tbb TBB::tbbmalloc doctest::doctest fmt::fmt nanobench::nanobench) +target_link_libraries(tests libqbsp liblight libvis libbsputil common TBB::tbb TBB::tbbmalloc doctest::doctest fmt::fmt nanobench::nanobench) target_compile_definitions(tests PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)