Skip to content

Commit

Permalink
cmake: Clean and update
Browse files Browse the repository at this point in the history
Signed-off-by: sekaiacg <[email protected]>
  • Loading branch information
sekaiacg committed Jan 26, 2025
1 parent e96c67d commit 66f7c01
Show file tree
Hide file tree
Showing 31 changed files with 525 additions and 350 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ stamp-h1
*.bak
CMakeCache.txt
CMakeFiles
cmake_install.cmake
cmake_install.cmake
out/
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
url = https://android.googlesource.com/platform/system/core.git
[submodule "src/selinux"]
path = src/selinux
url = https://github.com/SELinuxProject/selinux
url = https://android.googlesource.com/platform/external/selinux
23 changes: 0 additions & 23 deletions CMakeLists.txt

This file was deleted.

45 changes: 45 additions & 0 deletions build/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.20)
project(erofs-utils)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)

if(DEFINED EROFS_C_FLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EROFS_C_FLAGS}")
endif()

if(DEFINED EROFS_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EROFS_CXX_FLAGS}")
endif()

if (DEFINED EROFS_LINKER_FLAGS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EROFS_LINKER_FLAGS}")
else ()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -static -s")
endif()

set(MODULES_SRC "${PROJECT_SOURCE_DIR}/../../src")
set(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../..")

# git clone submodule
execute_process(COMMAND git submodule init)
execute_process(COMMAND git submodule update)

# thrid part library
add_subdirectory("${MODULES_SRC}/lz4/build/cmake" "modules/lz4")

# header
include_directories(
"${PROJECT_SOURCE_DIR}/lib"
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src/lz4/lib"
"${MODULES_SRC}/core/libcutils/include"
"${MODULES_SRC}/e2fsprogs/lib"
"${MODULES_SRC}/e2fsprogs/lib/uuid"
"${MODULES_SRC}/selinux/libselinux/include"
"${MODULES_SRC}/logging/liblog/include"
)

# start building
add_subdirectory(modules)
add_subdirectory(erofs-tools)
File renamed without changes.
9 changes: 9 additions & 0 deletions build/cmake/erofs-tools/dump.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(TARGET dump.erofs)

file(GLOB DUMP_SRCS "${PROJECT_SOURCE_DIR}/dump/*.c")

add_executable(${TARGET} ${DUMP_SRCS})

target_compile_options(${TARGET} PRIVATE ${EROFS_UTILS_DEFAULTS_CFLAGS})

target_link_libraries(${TARGET} erofs)
9 changes: 9 additions & 0 deletions build/cmake/erofs-tools/fsck.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(TARGET fsck.erofs)

file(GLOB FSCK_SRCS "${PROJECT_SOURCE_DIR}/fsck/*.c")

add_executable(${TARGET} ${FSCK_SRCS})

target_compile_options(${TARGET} PRIVATE ${EROFS_UTILS_DEFAULTS_CFLAGS})

target_link_libraries(${TARGET} erofs)
File renamed without changes.
9 changes: 9 additions & 0 deletions build/cmake/erofs-tools/mkfs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(TARGET mkfs.erofs)

file(GLOB MKFS_SRCS "${PROJECT_SOURCE_DIR}/mkfs/*.c")

add_executable(${TARGET} ${MKFS_SRCS})

target_compile_options(${TARGET} PRIVATE ${EROFS_UTILS_DEFAULTS_CFLAGS})

target_link_libraries(${TARGET} erofs)
6 changes: 5 additions & 1 deletion src/CMakeLists.txt → build/cmake/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ include(liblog.cmake)
include(libcutils.cmake)
include(libselinux.cmake)
include(liberofs.cmake)
include(libpcre.cmake)
include(libpcre2.cmake)

if (CMAKE_SYSTEM_NAME MATCHES "Android")
include(libpackagelistparser.cmake)
endif()
48 changes: 48 additions & 0 deletions build/cmake/modules/libbase.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
set(TARGET base)

set(TARGET_SRC_DIR "${MODULES_SRC}/libbase")

set(TARGET_CFLAGS
"-Wall"
"-Werror"
"-Wextra"
"-Wexit-time-destructors"
)

set(LIBBASE_SRCS
"${TARGET_SRC_DIR}/abi_compatibility.cpp"
"${TARGET_SRC_DIR}/chrono_utils.cpp"
"${TARGET_SRC_DIR}/cmsg.cpp"
"${TARGET_SRC_DIR}/file.cpp"
"${TARGET_SRC_DIR}/hex.cpp"
"${TARGET_SRC_DIR}/logging.cpp"
"${TARGET_SRC_DIR}/mapped_file.cpp"
"${TARGET_SRC_DIR}/parsebool.cpp"
"${TARGET_SRC_DIR}/parsenetaddress.cpp"
"${TARGET_SRC_DIR}/posix_strerror_r.cpp"
"${TARGET_SRC_DIR}/process.cpp"
"${TARGET_SRC_DIR}/properties.cpp"
"${TARGET_SRC_DIR}/stringprintf.cpp"
"${TARGET_SRC_DIR}/strings.cpp"
"${TARGET_SRC_DIR}/threads.cpp"
"${TARGET_SRC_DIR}/test_utils.cpp"
)

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND LIBBASE_SRCS "${TARGET_SRC_DIR}/errors_unix.cpp" )
elseif (CMAKE_SYSTEM_NAME MATCHES "Android")
list(APPEND TARGET_CFLAGS
"-D_FILE_OFFSET_BITS=64"
)
endif()

add_library(${TARGET} STATIC ${LIBBASE_SRCS})

target_include_directories(${TARGET} PRIVATE
"${TARGET_SRC_DIR}/include"
"${MODULES_SRC}/core/include"
)

target_compile_options(${TARGET} PRIVATE $<$<COMPILE_LANGUAGE:C>:${TARGET_CFLAGS}> $<$<COMPILE_LANGUAGE:CXX>:${TARGET_CPPFLAGS}>)

target_link_libraries(${TARGET} log)
87 changes: 87 additions & 0 deletions build/cmake/modules/libcutils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
set(TARGET cutils)

set(TARGET_SRC_DIR "${MODULES_SRC}/core/libcutils")

set(TARGET_CFLAGS
"-Wno-exit-time-destructors"
"-Wall"
"-Wextra"
)

set(LIBCUTILS_SRCS
"${TARGET_SRC_DIR}/config_utils.cpp"
"${TARGET_SRC_DIR}/iosched_policy.cpp"
"${TARGET_SRC_DIR}/load_file.cpp"
"${TARGET_SRC_DIR}/native_handle.cpp"
"${TARGET_SRC_DIR}/properties.cpp"
"${TARGET_SRC_DIR}/record_stream.cpp"
"${TARGET_SRC_DIR}/strlcpy.c"
"${TARGET_SRC_DIR}/threads.cpp"
)
set(LIBCUTILS_NONWINDOWS_SRCS
"${TARGET_SRC_DIR}/fs.cpp"
"${TARGET_SRC_DIR}/hashmap.cpp"
"${TARGET_SRC_DIR}/multiuser.cpp"
"${TARGET_SRC_DIR}/str_parms.cpp"
)

set(LIBCUTILS_SOCKET_SRCS
"${TARGET_SRC_DIR}/sockets.cpp"
)
set(LIBCUTILS_SOCKET_NONWINDOWS_SRCS
"${TARGET_SRC_DIR}/socket_inaddr_any_server_unix.cpp"
"${TARGET_SRC_DIR}/socket_local_client_unix.cpp"
"${TARGET_SRC_DIR}/socket_local_server_unix.cpp"
"${TARGET_SRC_DIR}/socket_network_client_unix.cpp"
"${TARGET_SRC_DIR}/sockets_unix.cpp"
)

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND LIBCUTILS_SRCS
${LIBCUTILS_SOCKET_SRCS}
${LIBCUTILS_NONWINDOWS_SRCS}
${LIBCUTILS_SOCKET_NONWINDOWS_SRCS}
"${TARGET_SRC_DIR}/ashmem-host.cpp"
"${TARGET_SRC_DIR}/canned_fs_config.cpp"
"${TARGET_SRC_DIR}/fs_config.cpp"
"${TARGET_SRC_DIR}/trace-host.cpp"
)
elseif (CMAKE_SYSTEM_NAME MATCHES "Android")
list(APPEND LIBCUTILS_SOCKET_SRCS
"${TARGET_SRC_DIR}/android_get_control_file.cpp"
"${TARGET_SRC_DIR}/socket_inaddr_any_server_unix.cpp"
"${TARGET_SRC_DIR}/socket_local_client_unix.cpp"
"${TARGET_SRC_DIR}/socket_local_server_unix.cpp"
"${TARGET_SRC_DIR}/socket_network_client_unix.cpp"
"${TARGET_SRC_DIR}/sockets_unix.cpp"
)
list(APPEND LIBCUTILS_SRCS
${LIBCUTILS_SOCKET_SRCS}
${LIBCUTILS_SOCKET_NONWINDOWS_SRCS}
${LIBCUTILS_NONWINDOWS_SRCS}
"${TARGET_SRC_DIR}/android_reboot.cpp"
"${TARGET_SRC_DIR}/ashmem-dev.cpp"
"${TARGET_SRC_DIR}/canned_fs_config.cpp"
"${TARGET_SRC_DIR}/fs_config.cpp"
"${TARGET_SRC_DIR}/klog.cpp"
"${TARGET_SRC_DIR}/partition_utils.cpp"
"${TARGET_SRC_DIR}/qtaguid.cpp"
"${TARGET_SRC_DIR}/trace-dev.cpp"
"${TARGET_SRC_DIR}/uevent.cpp"
)
endif()

add_library(${TARGET} STATIC ${LIBCUTILS_SRCS})

target_include_directories(${TARGET} PRIVATE
"${TARGET_SRC_DIR}/include"
"${MODULES_SRC}/core/libutils/include"
"${MODULES_SRC}/libbase/include"
)

target_compile_options(${TARGET} PRIVATE ${TARGET_CFLAGS})

target_link_libraries(${TARGET}
base
log
)
57 changes: 57 additions & 0 deletions build/cmake/modules/liberofs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
set(TARGET erofs)

set(TARGET_SRC_DIR "${PROJECT_SOURCE_DIR}/lib")

set(EROFS_UTILS_DEFAULTS_CFLAGS
"-Wall"
"-Wno-ignored-qualifiers"
"-Wno-pointer-arith"
"-Wno-unused-parameter"
"-Wno-unused-function"
"-DHAVE_FALLOCATE"
"-DHAVE_LINUX_TYPES_H"
"-DHAVE_LIBSELINUX"
"-DHAVE_LIBUUID"
"-DLZ4_ENABLED"
"-DLZ4HC_ENABLED"
"-DWITH_ANDROID"
"-DHAVE_MEMRCHR"
CACHE INTERNAL "erofs_utils_defaults_cflags"
)

set(LIBEROFS_SRCS
"${TARGET_SRC_DIR}/config.c"
"${TARGET_SRC_DIR}/io.c"
"${TARGET_SRC_DIR}/cache.c"
"${TARGET_SRC_DIR}/super.c"
"${TARGET_SRC_DIR}/inode.c"
"${TARGET_SRC_DIR}/xattr.c"
"${TARGET_SRC_DIR}/exclude.c"
"${TARGET_SRC_DIR}/namei.c"
"${TARGET_SRC_DIR}/data.c"
"${TARGET_SRC_DIR}/compress.c"
"${TARGET_SRC_DIR}/compressor.c"
"${TARGET_SRC_DIR}/zmap.c"
"${TARGET_SRC_DIR}/decompress.c"
"${TARGET_SRC_DIR}/compress_hints.c"
"${TARGET_SRC_DIR}/hashmap.c"
"${TARGET_SRC_DIR}/sha256.c"
"${TARGET_SRC_DIR}/blobchunk.c"
"${TARGET_SRC_DIR}/dir.c"
"${TARGET_SRC_DIR}/block_list.c"
"${TARGET_SRC_DIR}/compressor_lz4.c"
"${TARGET_SRC_DIR}/compressor_lz4hc.c"
)

add_library(${TARGET} STATIC ${LIBEROFS_SRCS})

target_compile_options(${TARGET} PRIVATE ${EROFS_UTILS_DEFAULTS_CFLAGS})

target_link_libraries(${TARGET}
base
cutils
ext2_uuid
log
lz4_static
selinux
)
25 changes: 25 additions & 0 deletions build/cmake/modules/libext2_uuid.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
set(TARGET ext2_uuid)

set(TARGET_SRC_DIR "${MODULES_SRC}/e2fsprogs/lib/uuid")

set(TARGET_CFLAGS
"-Wno-unused-function"
"-Wno-unused-parameter"
)

set(LIBEXT2_UUID_SRCS
"${TARGET_SRC_DIR}/clear.c"
"${TARGET_SRC_DIR}/compare.c"
"${TARGET_SRC_DIR}/copy.c"
"${TARGET_SRC_DIR}/gen_uuid.c"
"${TARGET_SRC_DIR}/isnull.c"
"${TARGET_SRC_DIR}/pack.c"
"${TARGET_SRC_DIR}/parse.c"
"${TARGET_SRC_DIR}/unpack.c"
"${TARGET_SRC_DIR}/unparse.c"
"${TARGET_SRC_DIR}/uuid_time.c"
)

add_library(${TARGET} STATIC ${LIBEXT2_UUID_SRCS})

target_compile_options(${TARGET} PRIVATE $<$<COMPILE_LANGUAGE:C>:${TARGET_CFLAGS}>)
44 changes: 44 additions & 0 deletions build/cmake/modules/liblog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
set(TARGET log)

set(TARGET_SRC_DIR "${MODULES_SRC}/logging/liblog")

set(TARGET_CFLAGS
"-Wall"
"-Wextra"
"-Wexit-time-destructors"
"-DLIBLOG_LOG_TAG=1006"
"-DSNET_EVENT_LOG_TAG=1397638484"
)

set(LIBLOG_SRCS
"${TARGET_SRC_DIR}/log_event_list.cpp"
"${TARGET_SRC_DIR}/log_event_write.cpp"
"${TARGET_SRC_DIR}/logger_name.cpp"
"${TARGET_SRC_DIR}/logger_read.cpp"
"${TARGET_SRC_DIR}/logger_write.cpp"
"${TARGET_SRC_DIR}/logprint.cpp"
"${TARGET_SRC_DIR}/properties.cpp"
)
set(LIBLOG_TARGET_SRCS
"${TARGET_SRC_DIR}/event_tag_map.cpp"
"${TARGET_SRC_DIR}/log_time.cpp"
"${TARGET_SRC_DIR}/pmsg_reader.cpp"
"${TARGET_SRC_DIR}/pmsg_writer.cpp"
"${TARGET_SRC_DIR}/logd_reader.cpp"
"${TARGET_SRC_DIR}/logd_writer.cpp"
)

if (CMAKE_SYSTEM_NAME MATCHES "Android")
list(APPEND LIBLOG_SRCS ${LIBLOG_TARGET_SRCS})
endif()

add_library(${TARGET} STATIC ${LIBLOG_SRCS})

target_include_directories(${TARGET} PRIVATE
"${TARGET_SRC_DIR}/include"
"${MODULES_SRC}/core/include"
"${MODULES_SRC}/core/libcutils/include"
"${MODULES_SRC}/libbase/include"
)

target_compile_options(${TARGET} PRIVATE ${TARGET_CFLAGS})
Loading

0 comments on commit 66f7c01

Please sign in to comment.