Change cmakelists
This commit is contained in:
@@ -4,11 +4,18 @@ project(
|
||||
VERSION 1.0
|
||||
LANGUAGES C)
|
||||
|
||||
# ------------------------------------------------
|
||||
# C standard — no compiler extensions
|
||||
# ------------------------------------------------
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_EXTENSIONS OFF)
|
||||
|
||||
# Export compile_commands.json (clangd / IDEs)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# ------------------------------------------------
|
||||
# Detectar si este proyecto es el principal
|
||||
# Is this the root project or embedded (CPM / FetchContent)?
|
||||
# ------------------------------------------------
|
||||
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
|
||||
set(ARENA_IS_TOP_LEVEL ON)
|
||||
@@ -16,23 +23,75 @@ else()
|
||||
set(ARENA_IS_TOP_LEVEL OFF)
|
||||
endif()
|
||||
|
||||
# Opciones
|
||||
option(ARRAYLIST_BUILD_TESTS "Build arena tests" ${ARENA_IS_TOP_LEVEL})
|
||||
option(ARRAYLIST_ENABLE_SANITIZERS "Enable sanitizers for tests" ON)
|
||||
# ------------------------------------------------
|
||||
# Options
|
||||
# ------------------------------------------------
|
||||
option(ARENA_BUILD_TESTS "Build arena tests" ${ARENA_IS_TOP_LEVEL})
|
||||
option(ARENA_BUILD_EXAMPLE "Build arena example" ${ARENA_IS_TOP_LEVEL})
|
||||
option(ARENA_ENABLE_INSTALL "Install arena" ${ARENA_IS_TOP_LEVEL})
|
||||
option(ARENA_ENABLE_SANITIZERS "Enable Address Sanitizer in tests" ON)
|
||||
|
||||
# Librería
|
||||
# ------------------------------------------------
|
||||
# Portable warning flags
|
||||
# ------------------------------------------------
|
||||
if(MSVC)
|
||||
set(ARENA_WARNING_FLAGS /W4)
|
||||
else()
|
||||
set(ARENA_WARNING_FLAGS -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
|
||||
# ================================================================
|
||||
# LIBRARY
|
||||
# ================================================================
|
||||
add_library(arena src/arena.c)
|
||||
|
||||
# Namespaced alias → consumers can write arena::arena
|
||||
add_library(arena::arena ALIAS arena)
|
||||
|
||||
target_include_directories(
|
||||
arena PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
target_compile_options(arena PRIVATE -Wall -Wextra -Wpedantic)
|
||||
# Propagate C11 requirement to consumers
|
||||
target_compile_features(arena PUBLIC c_std_11)
|
||||
|
||||
# ------------------------
|
||||
# Testing
|
||||
# ------------------------
|
||||
# Warnings only for the lib itself, not propagated
|
||||
target_compile_options(arena PRIVATE ${ARENA_WARNING_FLAGS})
|
||||
|
||||
# ================================================================
|
||||
# EXAMPLE (optional, only when top-level)
|
||||
# ================================================================
|
||||
if(ARENA_BUILD_EXAMPLE)
|
||||
add_executable(arena_example src/main.c)
|
||||
target_link_libraries(arena_example PRIVATE arena)
|
||||
endif()
|
||||
|
||||
# ================================================================
|
||||
# TESTS
|
||||
# ================================================================
|
||||
if(ARENA_BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
# ================================================================
|
||||
# INSTALL
|
||||
# ================================================================
|
||||
if(ARENA_ENABLE_INSTALL)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
install(
|
||||
TARGETS arena
|
||||
EXPORT arenaTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
install(
|
||||
EXPORT arenaTargets
|
||||
FILE arenaTargets.cmake
|
||||
NAMESPACE arena::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/arena)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user