forget what is updated.

This commit is contained in:
Youmu Liu
2025-10-23 18:24:52 +08:00
parent affaf03845
commit 395872f88f
4 changed files with 90 additions and 38 deletions
+36
View File
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.16)
project(StgSharp.Native C)
# Include helper for external libraries if present
include(${CMAKE_CURRENT_LIST_DIR}/ExternalLibs.cmake OPTIONAL)
# Add main source directory
# Follow naming convention: prefer sn-src/sn-head (StgSharp native naming).
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/sn-src)
add_subdirectory(sn-src)
elseif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/src)
add_subdirectory(src)
else()
message(STATUS "No sn-src/ or src/ directory in StgSharp.Native; create one to add sources.")
endif()
# Register include directories according to naming convention: sn-head preferred
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/sn-head)
include_directories(${CMAKE_CURRENT_LIST_DIR}/sn-head)
elseif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
endif()
# Discover external libraries laid out under external/<libname> (each with head/ and lib/)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/external)
file(GLOB EXTERNAL_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external/*)
foreach(_d ${EXTERNAL_DIRS})
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/${_d}")
if(COMMAND use_external_lib)
use_external_lib(${_d} "${CMAKE_CURRENT_SOURCE_DIR}/external/${_d}")
else()
message(STATUS "External lib '${_d}' found at external/${_d} (no use_external_lib defined).")
endif()
endif()
endforeach()
endif()
+30
View File
@@ -0,0 +1,30 @@
# Helper for external libs layout: external/<libname>/{head,lib}
# Provides function `use_external_lib(<name> <path>)` that sets include directories
# and attempts to link static/shared libs found under lib/.
function(use_external_lib NAME PATH)
# Expect headers in ${PATH}/head and libs in ${PATH}/lib
set(HEAD_DIR "${PATH}/head")
set(LIB_DIR "${PATH}/lib")
if(EXISTS "${HEAD_DIR}")
message(STATUS "Registering external include: ${HEAD_DIR}")
include_directories(${HEAD_DIR})
else()
message(WARNING "External lib ${NAME} missing head/ directory at ${HEAD_DIR}")
endif()
if(EXISTS "${LIB_DIR}")
# try to find static/shared libs inside LIB_DIR
file(GLOB LIB_FILES RELATIVE ${LIB_DIR} ${LIB_DIR}/*)
foreach(_lib ${LIB_FILES})
if(_lib MATCHES ".*\\.(a|lib|so|dylib)$")
message(STATUS "Found library for ${NAME}: ${LIB_DIR}/${_lib}")
# Consumer targets should link explicitly; provide variable for convenience
set(EXTERNAL_LIB_${NAME} "${LIB_DIR}/${_lib}" PARENT_SCOPE)
endif()
endforeach()
else()
message(STATUS "No lib/ directory for external lib ${NAME} at ${LIB_DIR}")
endif()
endfunction()
+11
View File
@@ -0,0 +1,11 @@
StgSharp.Native layout
Conventions:
- src/ : project C sources and CMakeLists.txt calling add_library/add_executable
- include/ : public headers (if used)
- external/ : third-party libraries, each library lives in its own folder
- <libname>/
- head/ : header files for the library
- lib/ : static or shared lib files (or CMake build for that lib)
The root `CMakeLists.txt` in this folder includes `ExternalLibs.cmake` if present.