From e7dac8721c56bdad3d25499f8794362e12e487d9 Mon Sep 17 00:00:00 2001 From: craftablescience Date: Mon, 22 Jul 2024 17:22:23 -0400 Subject: [PATCH] feat(cmake): add support for precompiled headers, module definitions --- CMakeLists.txt | 4 ++-- cmake/AddPrettyParser.cmake | 12 +++++++++--- lang/c/src/steamppc/_steamppc.cmake | 3 ++- lang/c/src/viceppc/_viceppc.cmake | 3 ++- lang/c/src/vpkppc/_vpkppc.cmake | 6 ++++-- src/bsppp/_bsppp.cmake | 3 ++- src/dmxpp/_dmxpp.cmake | 3 ++- src/fgdpp/_fgdpp.cmake | 3 ++- src/kvpp/_kvpp.cmake | 3 ++- src/mdlpp/_mdlpp.cmake | 4 +++- src/sourcepp/_sourcepp.cmake | 9 +++++++-- src/steampp/_steampp.cmake | 4 +++- src/vicepp/_vicepp.cmake | 4 +++- src/vpkpp/_vpkpp.cmake | 5 ++++- src/vtfpp/_vtfpp.cmake | 5 ++++- test/vpkpp.cpp | 7 ------- 16 files changed, 51 insertions(+), 27 deletions(-) delete mode 100644 test/vpkpp.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1000d3f02..7fd82d196 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.25 FATAL_ERROR) +cmake_minimum_required(VERSION 3.28 FATAL_ERROR) # Set defaults before project call @@ -92,7 +92,7 @@ add_sourcepp_library(kvpp) add_sourcepp_library(mdlpp) add_sourcepp_library(steampp C) add_sourcepp_library(vicepp C CSHARP) -add_sourcepp_library(vpkpp C CSHARP) +add_sourcepp_library(vpkpp C CSHARP NO_TEST) add_sourcepp_library(vtfpp) diff --git a/cmake/AddPrettyParser.cmake b/cmake/AddPrettyParser.cmake index 40d1f1621..9aece6961 100644 --- a/cmake/AddPrettyParser.cmake +++ b/cmake/AddPrettyParser.cmake @@ -1,15 +1,21 @@ # Add a new parser library function(add_pretty_parser TARGET) - cmake_parse_arguments(PARSE_ARGV 1 OPTIONS "C" "" "DEPS;SOURCES") + cmake_parse_arguments(PARSE_ARGV 1 OPTIONS "C" "" "DEPS;PRECOMPILED_HEADERS;SOURCES;MODULES") if(OPTIONS_C) - add_library(${TARGET}c SHARED ${${PROJECT_NAME}c_SOURCES} ${OPTIONS_SOURCES}) + add_library(${TARGET}c SHARED ${${PROJECT_NAME}c_SOURCES} ${OPTIONS_PRECOMPILED_HEADERS} ${OPTIONS_SOURCES}) set_target_properties(${TARGET}c PROPERTIES PREFIX "") target_link_libraries(${TARGET}c PRIVATE ${TARGET}) target_include_directories(${TARGET}c PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include") set(TARGET "${TARGET}c") else() - add_library(${TARGET} STATIC ${OPTIONS_SOURCES}) + add_library(${TARGET} STATIC ${OPTIONS_PRECOMPILED_HEADERS} ${OPTIONS_SOURCES}) + if(NOT ("MODULES" IN_LIST OPTIONS_UNPARSED_ARGUMENTS)) + target_sources(${TARGET} PUBLIC FILE_SET CXX_MODULES FILES ${OPTIONS_MODULES}) + endif() + endif() + if(NOT ("PRECOMPILED_HEADERS" IN_LIST OPTIONS_UNPARSED_ARGUMENTS)) + target_precompile_headers(${TARGET} PUBLIC ${OPTIONS_HEADERS}) endif() target_link_libraries(${TARGET} PUBLIC ${PROJECT_NAME}) target_link_libraries(${TARGET} PRIVATE ${OPTIONS_DEPS}) diff --git a/lang/c/src/steamppc/_steamppc.cmake b/lang/c/src/steamppc/_steamppc.cmake index f0890e997..fae95972b 100644 --- a/lang/c/src/steamppc/_steamppc.cmake +++ b/lang/c/src/steamppc/_steamppc.cmake @@ -1,4 +1,5 @@ -add_pretty_parser(steampp C SOURCES +add_pretty_parser(steampp C + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/steamppc/Convert.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/steamppc/steampp.h" "${CMAKE_CURRENT_LIST_DIR}/Convert.cpp" diff --git a/lang/c/src/viceppc/_viceppc.cmake b/lang/c/src/viceppc/_viceppc.cmake index 65da8350b..041c3a596 100644 --- a/lang/c/src/viceppc/_viceppc.cmake +++ b/lang/c/src/viceppc/_viceppc.cmake @@ -1,3 +1,4 @@ -add_pretty_parser(vicepp C SOURCES +add_pretty_parser(vicepp C + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/viceppc/vicepp.h" "${CMAKE_CURRENT_LIST_DIR}/vicepp.cpp") diff --git a/lang/c/src/vpkppc/_vpkppc.cmake b/lang/c/src/vpkppc/_vpkppc.cmake index df29261e9..3a4d00707 100644 --- a/lang/c/src/vpkppc/_vpkppc.cmake +++ b/lang/c/src/vpkppc/_vpkppc.cmake @@ -1,4 +1,5 @@ -add_pretty_parser(vpkpp C SOURCES +add_pretty_parser(vpkpp C + PRECOMPILED_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/BSP.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/FPX.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/GCF.h" @@ -9,12 +10,13 @@ add_pretty_parser(vpkpp C SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/VPK.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/ZIP.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Attribute.h" - "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Convert.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Entry.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Options.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/PackFile.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/PackFileType.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/vpkpp.h" + SOURCES + "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Convert.hpp" "${CMAKE_CURRENT_LIST_DIR}/format/BSP.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/FPX.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/GCF.cpp" diff --git a/src/bsppp/_bsppp.cmake b/src/bsppp/_bsppp.cmake index f77f030ba..1d28b6ff3 100644 --- a/src/bsppp/_bsppp.cmake +++ b/src/bsppp/_bsppp.cmake @@ -1,3 +1,4 @@ -add_pretty_parser(bsppp DEPS vpkpp SOURCES +add_pretty_parser(bsppp + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/include/bsppp/bsppp.h" "${CMAKE_CURRENT_LIST_DIR}/bsppp.cpp") diff --git a/src/dmxpp/_dmxpp.cmake b/src/dmxpp/_dmxpp.cmake index f4c5e9c34..8675cd1b7 100644 --- a/src/dmxpp/_dmxpp.cmake +++ b/src/dmxpp/_dmxpp.cmake @@ -1,4 +1,5 @@ -add_pretty_parser(dmxpp SOURCES +add_pretty_parser(dmxpp + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/include/dmxpp/structs/Value.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/dmxpp/dmxpp.h" "${CMAKE_CURRENT_LIST_DIR}/structs/Value.cpp" diff --git a/src/fgdpp/_fgdpp.cmake b/src/fgdpp/_fgdpp.cmake index b8e3fdb53..1d8fc2571 100644 --- a/src/fgdpp/_fgdpp.cmake +++ b/src/fgdpp/_fgdpp.cmake @@ -1,3 +1,4 @@ -add_pretty_parser(fgdpp SOURCES +add_pretty_parser(fgdpp + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/include/fgdpp/fgdpp.h" "${CMAKE_CURRENT_LIST_DIR}/fgdpp.cpp") diff --git a/src/kvpp/_kvpp.cmake b/src/kvpp/_kvpp.cmake index 1c9d4e6f7..94adf5bc0 100644 --- a/src/kvpp/_kvpp.cmake +++ b/src/kvpp/_kvpp.cmake @@ -1,3 +1,4 @@ -add_pretty_parser(kvpp SOURCES +add_pretty_parser(kvpp + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/include/kvpp/kvpp.h" "${CMAKE_CURRENT_LIST_DIR}/kvpp.cpp") diff --git a/src/mdlpp/_mdlpp.cmake b/src/mdlpp/_mdlpp.cmake index 8744c0040..86f313920 100644 --- a/src/mdlpp/_mdlpp.cmake +++ b/src/mdlpp/_mdlpp.cmake @@ -1,9 +1,11 @@ -add_pretty_parser(mdlpp SOURCES +add_pretty_parser(mdlpp + PRECOMPILED_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/mdlpp/structs/Generic.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/mdlpp/structs/MDL.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/mdlpp/structs/VTX.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/mdlpp/structs/VVD.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/mdlpp/mdlpp.h" + SOURCES "${CMAKE_CURRENT_LIST_DIR}/structs/MDL.cpp" "${CMAKE_CURRENT_LIST_DIR}/structs/VTX.cpp" "${CMAKE_CURRENT_LIST_DIR}/structs/VVD.cpp" diff --git a/src/sourcepp/_sourcepp.cmake b/src/sourcepp/_sourcepp.cmake index 2cf60817e..fe9e93c03 100644 --- a/src/sourcepp/_sourcepp.cmake +++ b/src/sourcepp/_sourcepp.cmake @@ -1,4 +1,4 @@ -add_library(${PROJECT_NAME} STATIC +list(APPEND ${PROJECT_NAME}_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/crypto/Adler32.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/crypto/CRC32.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/crypto/MD5.h" @@ -12,7 +12,10 @@ add_library(${PROJECT_NAME} STATIC "${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/math/Vector.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/parser/Binary.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/parser/Text.h" - "${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/string/String.h" + "${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/string/String.h") + +add_library(${PROJECT_NAME} STATIC + ${${PROJECT_NAME}_HEADERS} "${CMAKE_CURRENT_LIST_DIR}/crypto/Adler32.cpp" "${CMAKE_CURRENT_LIST_DIR}/crypto/CRC32.cpp" "${CMAKE_CURRENT_LIST_DIR}/crypto/MD5.cpp" @@ -23,6 +26,8 @@ add_library(${PROJECT_NAME} STATIC "${CMAKE_CURRENT_LIST_DIR}/parser/Text.cpp" "${CMAKE_CURRENT_LIST_DIR}/string/String.cpp") +target_precompile_headers(${PROJECT_NAME} PUBLIC ${${PROJECT_NAME}_HEADERS}) + target_link_libraries(${PROJECT_NAME} PUBLIC bufferstream cryptopp::cryptopp) target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") diff --git a/src/steampp/_steampp.cmake b/src/steampp/_steampp.cmake index bfd0a10a3..7001d000c 100644 --- a/src/steampp/_steampp.cmake +++ b/src/steampp/_steampp.cmake @@ -1,3 +1,5 @@ -add_pretty_parser(steampp DEPS kvpp SOURCES +add_pretty_parser(steampp + DEPS kvpp + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/include/steampp/steampp.h" "${CMAKE_CURRENT_LIST_DIR}/steampp.cpp") diff --git a/src/vicepp/_vicepp.cmake b/src/vicepp/_vicepp.cmake index 26364bfdf..ee3be25eb 100644 --- a/src/vicepp/_vicepp.cmake +++ b/src/vicepp/_vicepp.cmake @@ -1,3 +1,5 @@ -add_pretty_parser(vicepp DEPS sourcepp_ice SOURCES +add_pretty_parser(vicepp + DEPS sourcepp_ice + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/include/vicepp/vicepp.h" "${CMAKE_CURRENT_LIST_DIR}/vicepp.cpp") diff --git a/src/vpkpp/_vpkpp.cmake b/src/vpkpp/_vpkpp.cmake index 418dc7522..e3446d328 100644 --- a/src/vpkpp/_vpkpp.cmake +++ b/src/vpkpp/_vpkpp.cmake @@ -1,4 +1,6 @@ -add_pretty_parser(vpkpp DEPS bsppp cryptopp::cryptopp kvpp MINIZIP::minizip SOURCES +add_pretty_parser(vpkpp + DEPS bsppp cryptopp::cryptopp kvpp MINIZIP::minizip + PRECOMPILED_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/BSP.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/FPX.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/GCF.h" @@ -14,6 +16,7 @@ add_pretty_parser(vpkpp DEPS bsppp cryptopp::cryptopp kvpp MINIZIP::minizip SOUR "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/PackFile.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/PackFileType.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/vpkpp.h" + SOURCES "${CMAKE_CURRENT_LIST_DIR}/format/BSP.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/FPX.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/GCF.cpp" diff --git a/src/vtfpp/_vtfpp.cmake b/src/vtfpp/_vtfpp.cmake index b262c5f06..261f3b760 100644 --- a/src/vtfpp/_vtfpp.cmake +++ b/src/vtfpp/_vtfpp.cmake @@ -1,7 +1,10 @@ -add_pretty_parser(vtfpp DEPS miniz sourcepp_stb SOURCES +add_pretty_parser(vtfpp + DEPS miniz sourcepp_stb + PRECOMPILED_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/vtfpp/ImageConversion.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vtfpp/ImageFormats.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vtfpp/vtfpp.h" + SOURCES "${CMAKE_CURRENT_LIST_DIR}/ImageConversion.cpp" "${CMAKE_CURRENT_LIST_DIR}/vtfpp.cpp") diff --git a/test/vpkpp.cpp b/test/vpkpp.cpp deleted file mode 100644 index 5905c948a..000000000 --- a/test/vpkpp.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -#include - -using namespace vpkpp; - -// todo: vpkpp tests