Skip to content

Commit 274a32a

Browse files
committed
add pkg-config and cmake config files, fix some compiler warnings and remove libs3util submodule
1 parent 236ca16 commit 274a32a

8 files changed

+52
-18
lines changed

.gitmodules

-4
This file was deleted.

CMakeLists.txt

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
11
cmake_minimum_required(VERSION 3.2.2)
2-
project(libs3dat)
2+
project(libs3dat VERSION 1.0.0)
33

44
option(PRIVATE_FILENAME "stop leaking complete path to file (should be enabled on distribution)" ON)
55

6-
add_subdirectory(libs3util)
7-
8-
include(CPack)
96
include(CTest)
107
include(TestBigEndian)
8+
include(CMakePackageConfigHelpers)
119

1210
set(CMAKE_C_FLAGS "-Wall")
1311
set(CMAKE_C_STANDARD 11)
1412
set(CMAKE_C_STANDARD_REQUIRED ON)
1513
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
1614
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
1715
set(CPACK_PACKAGE_NAME "libs3dat")
16+
set(CPACK_PACKAGE_VERSION ${libs3dat_VERSION})
17+
set(CPACK_PACKAGE_VERSION_MAJOR ${libs3dat_VERSION_MAJOR})
18+
set(CPACK_PACKAGE_VERSION_MINOR ${libs3dat_VERSION_MINOR})
19+
set(CPACK_PACKAGE_VERSION_PATCH ${libs3dat_VERSION_PATCH})
20+
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
21+
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
22+
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libs3util (=1.0.0)")
23+
include(CPack)
1824

1925
set(STRING_BUFFER 1024)
2026

2127
TEST_BIG_ENDIAN(IS_BE)
2228

29+
find_package(s3util REQUIRED)
30+
2331

2432
configure_file(config.h.in ${PROJECT_BINARY_DIR}/config.s3dat.h)
33+
configure_file(libs3dat.pc.in ${PROJECT_BINARY_DIR}/libs3dat.pc @ONLY)
2534

26-
include_directories(src ${PROJECT_BINARY_DIR} libs3util/src)
35+
include_directories(src ${PROJECT_BINARY_DIR} ${s3util_INCLUDE_DIRS})
2736

2837

2938
#s3dat
3039
file(GLOB_RECURSE s3dat_SOURCES "src/*.[ch]")
3140

3241
add_library(s3dat SHARED ${s3dat_SOURCES})
3342
target_link_libraries(s3dat s3util)
43+
target_include_directories(s3dat PUBLIC $<INSTALL_INTERFACE:include>)
3444

3545
add_executable(cli cli.c)
3646
target_link_libraries(cli s3dat)
@@ -62,8 +72,19 @@ if(glfw3_FOUND AND OpenGL_FOUND)
6272
target_include_directories(walk PUBLIC ${OPENGL_INCLUDE_DIRS} ${glfw3_INCLUDE_DIRS})
6373
endif()
6474

65-
install(TARGETS s3dat DESTINATION lib)
75+
write_basic_package_version_file(${PROJECT_BINARY_DIR}/s3datConfigVersion.cmake COMPATIBILITY ExactVersion)
76+
configure_package_config_file(s3datConfig.cmake.in s3datConfig.cmake INSTALL_DESTINATION lib/cmake/s3dat PATH_VARS CMAKE_INSTALL_PREFIX PROJECT_BINARY_DIR)
77+
78+
install(TARGETS s3dat EXPORT s3datTarget DESTINATION lib)
79+
install(EXPORT s3datTarget DESTINATION lib/cmake/s3dat)
80+
81+
#for find_package on build dirs
82+
export(TARGETS s3dat FILE s3datTarget.cmake)
83+
6684
install(FILES src/s3dat_ext.h src/s3dat.h DESTINATION include/s3dat)
85+
install(FILES ${PROJECT_BINARY_DIR}/libs3dat.pc DESTINATION lib/pkgconfig)
86+
install(FILES ${PROJECT_BINARY_DIR}/s3datConfigVersion.cmake ${PROJECT_BINARY_DIR}/s3datConfig.cmake DESTINATION lib/cmake/s3dat)
87+
install(FILES LICENSE DESTINATION share/doc/libs3dat)
6788

6889
add_executable(testme test.c)
6990
target_link_libraries(testme s3dat)

animation.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ int main(int argc, char** argv) {
113113
uint32_t file = ani_len > 0 ? s3dat_frame(ani, 0)->settler_file : 0;
114114

115115

116-
char img_name[31];
117-
snprintf(img_name, 30, "GFX/Siedler3_%.2i.f8007e01f.dat", file);
116+
char img_name[34];
117+
snprintf(img_name, 34, "GFX/Siedler3_%.2i.f8007e01f.dat", file);
118118
img_gfx = s3dat_new_malloc();
119119
s3dat_readfile_name(img_gfx, img_name, &ex);
120120
s3util_catch_exception(&ex);

libs3dat.pc.in

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
exec_prefix=${prefix}
3+
Requires: libs3util
4+
includedir=${prefix}/include
5+
libdir=${prefix}/lib
6+
7+
Name: libs3dat
8+
Description: A library that reads and writes dat files
9+
Version: @PROJECT_VERSION@
10+
Cflags: -I${includedir}/s3dat
11+
Libs: -L${libdir} -ls3dat

libs3util

-1
This file was deleted.

s3datConfig.cmake.in

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@PACKAGE_INIT@
2+
3+
include(${CMAKE_CURRENT_LIST_DIR}/s3datTarget.cmake)
4+
5+
if(NOT DEFINED s3dat_INCLUDE_DIRS)
6+
set(s3dat_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/src)
7+
endif()

src/extract.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void s3dat_read_packed_handler(s3dat_extracthandler_t* me, s3dat_res_t* res, s3u
5858
return;
5959
}
6060

61-
uint32_t raw_len;
61+
uint32_t raw_len = 0;
6262
uint32_t read_len;
6363
void* data;
6464

src/read.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ void s3dat_readfile(s3dat_t* handle, s3util_exception_t** throws) {
186186
}
187187
}
188188

189-
void s3dat_internal_read_index(s3dat_t* handle, uint32_t index, s3util_exception_t** throws) {
190-
s3dat_internal_seek_func(handle, index, S3UTIL_SEEK_SET, throws);
189+
void s3dat_internal_read_index(s3dat_t* handle, uint32_t index_pos, s3util_exception_t** throws) {
190+
s3dat_internal_seek_func(handle, index_pos, S3UTIL_SEEK_SET, throws);
191191
S3UTIL_HANDLE_EXCEPTION(s3dat_memset(handle), throws, __FILE__, __func__, __LINE__);
192192

193193
uint32_t index_type = S3DAT_INTERNAL_READ(32LE, handle, throws);
@@ -271,7 +271,7 @@ void s3dat_internal_read_index(s3dat_t* handle, uint32_t index, s3util_exception
271271
}
272272

273273
if(index_type == s3dat_settler || index_type == s3dat_torso || index_type == s3dat_shadow) {
274-
s3dat_seq_index_t* index;
274+
s3dat_seq_index_t* index = NULL;
275275
switch(index_type) {
276276
case s3dat_settler:
277277
index = handle->settler_index;
@@ -326,7 +326,7 @@ void s3dat_internal_read_index(s3dat_t* handle, uint32_t index, s3util_exception
326326
index->len = index_len;
327327
index->sequences = indices;
328328
} else {
329-
s3dat_index_t* index;
329+
s3dat_index_t* index = NULL;
330330
switch(index_type) {
331331
case s3dat_gui:
332332
index = handle->gui_index;

0 commit comments

Comments
 (0)