Skip to content

Commit

Permalink
feat(cmake): add support for precompiled headers, module definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Jul 22, 2024
1 parent 3fe5e20 commit e7dac87
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 27 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)


Expand Down
12 changes: 9 additions & 3 deletions cmake/AddPrettyParser.cmake
Original file line number Diff line number Diff line change
@@ -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})
Expand Down
3 changes: 2 additions & 1 deletion lang/c/src/steamppc/_steamppc.cmake
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lang/c/src/viceppc/_viceppc.cmake
Original file line number Diff line number Diff line change
@@ -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")
6 changes: 4 additions & 2 deletions lang/c/src/vpkppc/_vpkppc.cmake
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/bsppp/_bsppp.cmake
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 2 additions & 1 deletion src/dmxpp/_dmxpp.cmake
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/fgdpp/_fgdpp.cmake
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 2 additions & 1 deletion src/kvpp/_kvpp.cmake
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 3 additions & 1 deletion src/mdlpp/_mdlpp.cmake
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
9 changes: 7 additions & 2 deletions src/sourcepp/_sourcepp.cmake
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand All @@ -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")
4 changes: 3 additions & 1 deletion src/steampp/_steampp.cmake
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 3 additions & 1 deletion src/vicepp/_vicepp.cmake
Original file line number Diff line number Diff line change
@@ -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")
5 changes: 4 additions & 1 deletion src/vpkpp/_vpkpp.cmake
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion src/vtfpp/_vtfpp.cmake
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
7 changes: 0 additions & 7 deletions test/vpkpp.cpp

This file was deleted.

0 comments on commit e7dac87

Please sign in to comment.