forget what is updated.
This commit is contained in:
+13
-38
@@ -5,16 +5,20 @@ set(CMAKE_SYSTEM_VERSION 10.0 CACHE STRING "" FORCE)
|
|||||||
project(StgSharpDevelop C)
|
project(StgSharpDevelop C)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Set target arch type if empty. Visual studio solution generator provides it.
|
# Compiler and environment checks
|
||||||
################################################################################
|
################################################################################
|
||||||
if(NOT CMAKE_VS_PLATFORM_NAME)
|
|
||||||
set(CMAKE_VS_PLATFORM_NAME "x64")
|
|
||||||
endif()
|
|
||||||
message("${CMAKE_VS_PLATFORM_NAME} architecture in use")
|
|
||||||
|
|
||||||
if(NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Any CPU"
|
# Detect compiler family and allow only GCC or Clang when using CMake.
|
||||||
OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64"))
|
if(MSVC)
|
||||||
message(FATAL_ERROR "${CMAKE_VS_PLATFORM_NAME} arch is not supported!")
|
message(FATAL_ERROR "MSVC detected while configuring with CMake. This repository provides .vcxproj files for MSVC/Visual Studio.\nPlease open the solution in Visual Studio or use the existing .vcxproj files to build with MSVC. CMake-based MSVC builds are not supported by this project.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||||
|
message(STATUS "Using GCC: ${CMAKE_C_COMPILER}")
|
||||||
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||||
|
message(STATUS "Using Clang: ${CMAKE_C_COMPILER}")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unsupported compiler '${CMAKE_C_COMPILER_ID}'. Supported compilers for CMake builds are: GCC and Clang. MSVC users: use the provided .vcxproj and Visual Studio.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -26,35 +30,6 @@ set(CMAKE_CONFIGURATION_TYPES
|
|||||||
CACHE STRING "" FORCE
|
CACHE STRING "" FORCE
|
||||||
)
|
)
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Global compiler options
|
|
||||||
################################################################################
|
|
||||||
if(MSVC)
|
|
||||||
# remove default flags provided with CMake for MSVC
|
|
||||||
set(CMAKE_C_FLAGS "")
|
|
||||||
set(CMAKE_C_FLAGS_DEBUG "")
|
|
||||||
set(CMAKE_C_FLAGS_RELEASE "")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Global linker options
|
|
||||||
################################################################################
|
|
||||||
if(MSVC)
|
|
||||||
# remove default flags provided with CMake for MSVC
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "")
|
|
||||||
set(CMAKE_MODULE_LINKER_FLAGS "")
|
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "")
|
|
||||||
set(CMAKE_STATIC_LINKER_FLAGS "")
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS}")
|
|
||||||
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS}")
|
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS}")
|
|
||||||
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS}")
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS}")
|
|
||||||
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS}")
|
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS}")
|
|
||||||
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Nuget packages function stub.
|
# Nuget packages function stub.
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -82,5 +57,5 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|||||||
################################################################################
|
################################################################################
|
||||||
# Sub-projects
|
# Sub-projects
|
||||||
################################################################################
|
################################################################################
|
||||||
add_subdirectory(StgSharp.C)
|
add_subdirectory(StgSharp.Native)
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
@@ -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()
|
||||||
@@ -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.
|
||||||
Reference in New Issue
Block a user