Fix for cmakelist
This commit is contained in:
@@ -4,14 +4,18 @@ project(
|
||||
VERSION 1.0
|
||||
LANGUAGES C)
|
||||
|
||||
# ------------------------------------------------
|
||||
# Estandard C
|
||||
# ------------------------------------------------
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_EXTENSIONS OFF)
|
||||
|
||||
# clangd
|
||||
# Exportar compile_commands.json (clangd / IDEs)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# ------------------------------------------------
|
||||
# Detectar si este proyecto es el principal
|
||||
# Is Top project?
|
||||
# ------------------------------------------------
|
||||
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
|
||||
set(ARRAYLIST_IS_TOP_LEVEL ON)
|
||||
@@ -19,32 +23,76 @@ else()
|
||||
set(ARRAYLIST_IS_TOP_LEVEL OFF)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------
|
||||
# Opciones
|
||||
option(ARRAYLIST_BUILD_TESTS "Build arraylist tests" ${ARRAYLIST_IS_TOP_LEVEL})
|
||||
option(ARRAYLIST_ENABLE_SANITIZERS "Enable sanitizers for tests" ON)
|
||||
# ------------------------------------------------
|
||||
option(ARRAYLIST_BUILD_TESTS "Build tests" ${ARRAYLIST_IS_TOP_LEVEL})
|
||||
option(ARRAYLIST_BUILD_EXAMPLE "Build example" ${ARRAYLIST_IS_TOP_LEVEL})
|
||||
option(ARRAYLIST_ENABLE_INSTALL "Enable install" ${ARRAYLIST_IS_TOP_LEVEL})
|
||||
option(ARRAYLIST_ENABLE_SANITIZERS "Enable Sanitizers for test" ON)
|
||||
|
||||
# ------------------------
|
||||
# Library
|
||||
# ------------------------
|
||||
# ------------------------------------------------
|
||||
# Warning Flags (GCC/Clang vs MSVC)
|
||||
# ------------------------------------------------
|
||||
if(MSVC)
|
||||
set(ARRAYLIST_WARNING_FLAGS /W4)
|
||||
else()
|
||||
set(ARRAYLIST_WARNING_FLAGS -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------
|
||||
# Main Library
|
||||
# ------------------------------------------------
|
||||
add_library(arraylist src/arraylist.c)
|
||||
|
||||
# Alias con namespace → los consumidores via CPM/FetchContent pueden escribir
|
||||
# target_link_libraries(mi_app arraylist::arraylist)
|
||||
add_library(arraylist::arraylist ALIAS arraylist)
|
||||
|
||||
target_include_directories(
|
||||
arraylist PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
target_compile_options(arraylist PRIVATE -Wall -Wextra -Wpedantic)
|
||||
# Flagas only for compile lib
|
||||
target_compile_options(arraylist PRIVATE ${ARRAYLIST_WARNING_FLAGS})
|
||||
|
||||
# ------------------------
|
||||
# Example (opcional)
|
||||
# ------------------------
|
||||
add_executable(arraylist_example src/main.c)
|
||||
# Propagates c11 as requirement
|
||||
target_compile_features(arraylist PUBLIC c_std_11)
|
||||
|
||||
target_link_libraries(arraylist_example arraylist)
|
||||
# ------------------------------------------------
|
||||
# Example only built when is main proyect
|
||||
# ------------------------------------------------
|
||||
if(ARRAYLIST_BUILD_EXAMPLE)
|
||||
add_executable(arraylist_example src/main.c)
|
||||
target_link_libraries(arraylist_example PRIVATE arraylist)
|
||||
endif()
|
||||
|
||||
# ------------------------
|
||||
# Testing
|
||||
# ------------------------
|
||||
# ------------------------------------------------
|
||||
# Tests
|
||||
# ------------------------------------------------
|
||||
if(ARRAYLIST_BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------
|
||||
# Installation rules
|
||||
# ------------------------------------------------
|
||||
if(ARRAYLIST_ENABLE_INSTALL)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
install(
|
||||
TARGETS arraylist
|
||||
EXPORT arraylistTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
install(
|
||||
EXPORT arraylistTargets
|
||||
FILE arraylistTargets.cmake
|
||||
NAMESPACE arraylist::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/arraylist)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user