|
| 1 | +--- CMakeLists.txt.orig 2025-08-30 18:33:06 UTC |
| 2 | ++++ CMakeLists.txt |
| 3 | +@@ -0,0 +1,75 @@ |
| 4 | ++cmake_minimum_required(VERSION 3.15) |
| 5 | ++ |
| 6 | ++project(OBUParse VERSION %%DISTVERSION%% LANGUAGES C) |
| 7 | ++ |
| 8 | ++# --- Set Standard Output Directories --- |
| 9 | ++set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 10 | ++set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 11 | ++set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 12 | ++ |
| 13 | ++# --- Build Options --- |
| 14 | ++# On MSVC, we only build static to avoid DLL export complexity and naming collisions. |
| 15 | ++# On other platforms (including MinGW on Windows), we can build both. |
| 16 | ++option(BUILD_SHARED_LIBS "Build the shared library" ON) |
| 17 | ++option(BUILD_STATIC_LIBS "Build the static library" OFF) |
| 18 | ++ |
| 19 | ++if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS) |
| 20 | ++ message(FATAL_ERROR "You must choose to build at least one library type.") |
| 21 | ++endif() |
| 22 | ++ |
| 23 | ++# --- Library Targets --- |
| 24 | ++ |
| 25 | ++if(BUILD_SHARED_LIBS) # This block will now be skipped on MSVC |
| 26 | ++ add_library(obuparse_shared SHARED obuparse.c) |
| 27 | ++ set_target_properties(obuparse_shared PROPERTIES |
| 28 | ++ OUTPUT_NAME "obuparse" |
| 29 | ++ VERSION ${PROJECT_VERSION} |
| 30 | ++ SOVERSION 2 |
| 31 | ++ EXPORT_NAME "shared" |
| 32 | ++ ) |
| 33 | ++ target_include_directories(obuparse_shared PUBLIC |
| 34 | ++ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> |
| 35 | ++ $<INSTALL_INTERFACE:include> |
| 36 | ++ ) |
| 37 | ++ add_library(OBUParse::shared ALIAS obuparse_shared) |
| 38 | ++endif() |
| 39 | ++ |
| 40 | ++if(BUILD_STATIC_LIBS) |
| 41 | ++ add_library(obuparse_static STATIC obuparse.c) |
| 42 | ++ # The naming collision only happens with MSVC, not MinGW. |
| 43 | ++ if(MSVC) |
| 44 | ++ set_target_properties(obuparse_static PROPERTIES OUTPUT_NAME "obuparses") |
| 45 | ++ else() |
| 46 | ++ set_target_properties(obuparse_static PROPERTIES OUTPUT_NAME "obuparse") |
| 47 | ++ endif() |
| 48 | ++ set_target_properties(obuparse_static PROPERTIES EXPORT_NAME "static") |
| 49 | ++ target_include_directories(obuparse_static PUBLIC |
| 50 | ++ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> |
| 51 | ++ $<INSTALL_INTERFACE:include> |
| 52 | ++ ) |
| 53 | ++ add_library(OBUParse::static ALIAS obuparse_static) |
| 54 | ++endif() |
| 55 | ++ |
| 56 | ++# --- Installation --- |
| 57 | ++include(GNUInstallDirs) |
| 58 | ++ |
| 59 | ++# Install the public header file |
| 60 | ++install(FILES obuparse.h |
| 61 | ++ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 62 | ++) |
| 63 | ++ |
| 64 | ++set(BUILT_TARGETS "") |
| 65 | ++if(TARGET obuparse_static) |
| 66 | ++ list(APPEND BUILT_TARGETS obuparse_static) |
| 67 | ++endif() |
| 68 | ++if(TARGET obuparse_shared) |
| 69 | ++ list(APPEND BUILT_TARGETS obuparse_shared) |
| 70 | ++endif() |
| 71 | ++ |
| 72 | ++# Install the library targets that were built, and the tool |
| 73 | ++install(TARGETS ${BUILT_TARGETS} |
| 74 | ++ EXPORT OBUParseTargets |
| 75 | ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 76 | ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 77 | ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 78 | ++) |
0 commit comments