Simplify find_include_dirs

This commit is contained in:
Tim Angus 2025-08-25 16:07:53 +01:00
parent bbdde5bdfc
commit 847cc42c4d
4 changed files with 7 additions and 30 deletions

View File

@ -10,7 +10,7 @@ set(INTERNAL_JPEG_DIR ${SOURCE_DIR}/thirdparty/jpeg-9f)
if(USE_INTERNAL_JPEG)
file(GLOB_RECURSE JPEG_SOURCES ${INTERNAL_JPEG_DIR}/j*.c)
disable_warnings(${JPEG_SOURCES})
find_include_dirs(JPEG_INCLUDE_DIRS ${JPEG_SOURCES})
find_include_dirs(JPEG_INCLUDE_DIRS ${INTERNAL_JPEG_DIR})
set(JPEG_DEFINITIONS USE_INTERNAL_JPEG)
list(APPEND RENDERER_LIBRARY_SOURCES ${JPEG_SOURCES})
else()

View File

@ -16,9 +16,8 @@ if(USE_INTERNAL_OPUS)
file(GLOB_RECURSE OPUS_SOURCES ${INTERNAL_OPUS_DIR}/*.c)
file(GLOB_RECURSE OPUSFILE_SOURCES ${INTERNAL_OPUSFILE_DIR}/*.c)
disable_warnings(${OPUS_SOURCES} ${OPUSFILE_SOURCES})
find_include_dirs(OPUS_INCLUDE_DIRS ${OPUS_SOURCES})
find_include_dirs(OPUSFILE_INCLUDE_DIRS ${OPUSFILE_SOURCES})
set(OPUS_INCLUDE_DIRS ${OPUS_INCLUDE_DIRS} ${OPUSFILE_INCLUDE_DIRS} ${INTERNAL_OPUSFILE_DIR}/include)
find_include_dirs(OPUS_INCLUDE_DIRS ${INTERNAL_OPUS_DIR})
find_include_dirs(OPUSFILE_INCLUDE_DIRS ${INTERNAL_OPUSFILE_DIR})
set(OPUS_DEFINITIONS OPUS_BUILD HAVE_LRINTF FLOATING_POINT FLOAT_APPROX USE_ALLOCA)
list(APPEND CLIENT_LIBRARY_SOURCES ${OPUS_SOURCES} ${OPUSFILE_SOURCES})
else()

View File

@ -6,7 +6,7 @@ set(INTERNAL_ZLIB_DIR ${SOURCE_DIR}/thirdparty/zlib-1.3.1)
if(USE_INTERNAL_ZLIB)
file(GLOB_RECURSE ZLIB_SOURCES ${INTERNAL_ZLIB_DIR}/*.c)
disable_warnings(ZLIB_SOURCES)
find_include_dirs(ZLIB_INCLUDE_DIRS ${ZLIB_SOURCES})
find_include_dirs(ZLIB_INCLUDE_DIRS ${INTERNAL_ZLIB_DIR})
set(ZLIB_DEFINITIONS NO_GZIP)
list(APPEND SERVER_LIBRARY_SOURCES ${ZLIB_SOURCES})
list(APPEND CLIENT_LIBRARY_SOURCES ${ZLIB_SOURCES})

View File

@ -1,30 +1,8 @@
include_guard(GLOBAL)
function(find_include_dirs OUT_VAR)
set(SOURCES ${ARGN})
# Get top most common directory prefix for all source files
set(COMMON_PATH "")
foreach(FILE IN LISTS SOURCES)
get_filename_component(DIR ${FILE} DIRECTORY)
file(REAL_PATH ${DIR} DIR)
if(COMMON_PATH STREQUAL "")
set(COMMON_PATH ${DIR})
else()
string(LENGTH ${COMMON_PATH} PREFIX_LEN)
while(NOT ${DIR} MATCHES "^${COMMON_PATH}(/|$)" AND PREFIX_LEN GREATER 0)
string(SUBSTRING ${COMMON_PATH} 0 ${PREFIX_LEN} COMMON_PATH)
math(EXPR PREFIX_LEN "${PREFIX_LEN} - 1")
endwhile()
endif()
endforeach()
if(NOT IS_DIRECTORY ${COMMON_PATH})
message(FATAL_ERROR "Could not determine common directory for source files")
endif()
# Recursively find directories that contain .h files under common directory
file(GLOB_RECURSE HEADER_FILES ${COMMON_PATH}/*.h)
function(find_include_dirs OUT_VAR LIBRARY_DIR)
# Recursively find directories that contain .h files under LIBRARY_DIR
file(GLOB_RECURSE HEADER_FILES ${LIBRARY_DIR}/*.h)
set(INCLUDE_DIRS "")
foreach(HEADER_FILE IN LISTS HEADER_FILES)
get_filename_component(HEADER_DIR ${HEADER_FILE} DIRECTORY)