Skip to content

Commit

Permalink
Rework build configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanoBilenchi committed Aug 25, 2024
1 parent 0a4740f commit e44df2d
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 269 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ jobs:
- name: Configure CMake
run: >
CC=clang cmake -B ${{env.build_dir}}
-DCOWL_CPP_TESTS=OFF
-DCOWL_LTO=OFF
-DCOWL_CLANG_TIDY=ON
-DCMAKE_COMPILE_WARNING_AS_ERROR=ON
- name: Build
run: cmake --build ${{env.build_dir}}
run: cmake --build ${{env.build_dir}} --target cowl-test cowl-bench cowl-examples cowl-tools

test:
name: Test
Expand Down Expand Up @@ -80,6 +82,11 @@ jobs:
--config ${{env.build_config}}
--target cowl-test cowl-cpp-test cowl-bench cowl-examples cowl-tools
- name: Debug
if: ${{always()}}
run: sed '4019q;d' ${{env.build_dir}}/src/reader/functional/cowl_func_yyparser.c
shell: bash

- name: Configure tests (Windows)
working-directory: ${{env.build_dir}}
if: runner.os == 'Windows'
Expand Down
63 changes: 34 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ project(Cowl
HOMEPAGE_URL "${COWL_VENDOR_URL}/cowl"
LANGUAGES C)

# Options
# Cache variables

option(COWL_EMBEDDED "Enable optimizations for embedded platforms" OFF)
option(COWL_LTO "Enable link-time optimization, if available" ON)
Expand All @@ -38,9 +38,10 @@ set(COWL_WRITERS "functional" CACHE STRING "List of enabled built-in writers (se

set(COWL_PROJECT_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(COWL_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(COWL_PUBLIC_HEADERS_DIR "${COWL_PROJECT_DIR}/include")
set(COWL_LIB_DIR "${COWL_PROJECT_DIR}/lib")
set(COWL_SRC_DIR "${COWL_PROJECT_DIR}/src")
set(COWL_PUBLIC_HEADERS_DIR "${COWL_PROJECT_DIR}/include")
set(COWL_PRIVATE_HEADERS_DIR "${COWL_SRC_DIR}")
set(COWL_READER_DIR "${COWL_SRC_DIR}/reader")
set(COWL_WRITER_DIR "${COWL_SRC_DIR}/writer")

Expand All @@ -50,19 +51,19 @@ set(COWL_EXAMPLES_DIR "${COWL_PROJECT_DIR}/examples")
set(COWL_TEST_DIR "${COWL_PROJECT_DIR}/test")
set(COWL_TOOLS_DIR "${COWL_PROJECT_DIR}/tools")

set(COWL_ULIB_DIR "${COWL_LIB_DIR}/ulib")
set(COWL_ULIB_UTILS_DIR "${COWL_ULIB_DIR}/utils")

set(COWL_HEADERS_OUT_DIR "${COWL_OUTPUT_DIR}/include")

# CMake settings

list(APPEND CMAKE_MODULE_PATH "${COWL_ULIB_UTILS_DIR}/cmake")

# Target settings

set(COWL_COMPILE_FEATURES c_std_11)

if(COWL_CLANG_TIDY)
set(COWL_CLANG_TIDY_COMMAND "clang-tidy")
if(CMAKE_COMPILE_WARNING_AS_ERROR)
list(APPEND COWL_CLANG_TIDY_COMMAND "-warnings-as-errors=*")
endif()
endif()

if(COWL_ENTITY_IDS)
list(APPEND COWL_PUBLIC_DEFINES COWL_ENTITY_IDS=1)
endif()
Expand All @@ -84,33 +85,31 @@ if(COWL_LTO)
check_ipo_supported(RESULT COWL_LTO_ENABLED)
endif()

if(COWL_CLANG_TIDY)
find_package(ClangTidy REQUIRED)
endif()

# uLib

option(ULIB_TINY "" ${COWL_EMBEDDED})
option(ULIB_LTO "" ${COWL_LTO})

if(NOT TARGET ulib)
add_subdirectory("${COWL_LIB_DIR}/ulib" EXCLUDE_FROM_ALL)
add_subdirectory("${COWL_ULIB_DIR}" EXCLUDE_FROM_ALL)
endif()

# Header dirs
# Sources

set(COWL_PUBLIC_HEADERS_DIRS "${COWL_PUBLIC_HEADERS_DIR}")
set(COWL_PRIVATE_HEADERS_DIRS "${COWL_SRC_DIR}")

# Header files

file(GLOB COWL_PUBLIC_HEADERS CONFIGURE_DEPENDS "${COWL_PUBLIC_HEADERS_DIR}/*.h")
get_target_property(COWL_ULIB_HEADERS ulib PUBLIC_HEADER)
list(APPEND COWL_PUBLIC_HEADERS ${COWL_ULIB_HEADERS})

# Sources

file(GLOB COWL_PRIVATE_HEADERS CONFIGURE_DEPENDS "${COWL_PRIVATE_HEADERS_DIR}/*.h")
file(GLOB COWL_SOURCES CONFIGURE_DEPENDS "${COWL_SRC_DIR}/*.c")

###############
### Targets ###
###############
###########
# Targets #
###########

# Readers

Expand Down Expand Up @@ -156,19 +155,25 @@ endif()

# Library

add_library(cowl ${COWL_LIBRARY_TYPE} ${COWL_SOURCES})
add_library(cowl ${COWL_LIBRARY_TYPE})
target_sources(cowl
PRIVATE ${COWL_SOURCES}
PRIVATE FILE_SET private_headers
TYPE HEADERS
BASE_DIRS ${COWL_PRIVATE_HEADERS_DIRS}
FILES ${COWL_PRIVATE_HEADERS}
PUBLIC FILE_SET public_headers
TYPE HEADERS
BASE_DIRS ${COWL_PUBLIC_HEADERS_DIRS}
FILES ${COWL_PUBLIC_HEADERS})
set_target_properties(cowl PROPERTIES
PUBLIC_HEADER "${COWL_PUBLIC_HEADERS}"
C_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON)
target_compile_features(cowl PRIVATE ${COWL_COMPILE_FEATURES})
target_compile_options(cowl PRIVATE ${COWL_WARNING_OPTIONS})
target_compile_definitions(cowl
PUBLIC ${COWL_PUBLIC_DEFINES}
PRIVATE ${COWL_PRIVATE_DEFINES})
target_include_directories(cowl
PUBLIC ${COWL_PUBLIC_HEADERS_DIRS}
PRIVATE ${COWL_PRIVATE_HEADERS_DIRS})
target_link_libraries(cowl PUBLIC ulib)
add_dependencies(cowl cowl-readers)

Expand All @@ -180,11 +185,11 @@ if(COWL_LTO_ENABLED)
set_property(TARGET cowl PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
endif()

if(COWL_CLANG_TIDY_COMMAND)
set_property(TARGET cowl PROPERTY C_CLANG_TIDY "${COWL_CLANG_TIDY_COMMAND}")
if(COWL_CLANG_TIDY)
clang_tidy_check(cowl)
endif()

install(TARGETS cowl ulib)
install(TARGETS cowl ulib FILE_SET public_headers)

# Subprojects

Expand Down
23 changes: 11 additions & 12 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Files and directories

set(DOCS_IMAGES_DIRECTORY "${COWL_DOCS_DIR}/img")
set(DOCS_OUTPUT_DIRECTORY "${COWL_OUTPUT_DIR}/docs")
set(SPHINX_INPUT_DIRECTORY "${COWL_DOCS_DIR}")
set(DOXYGEN_UTILS_DIRECTORY "${COWL_DOCS_DIR}/doxygen")
set(COWL_ICON "${DOCS_IMAGES_DIRECTORY}/cowl_logo.png")
list(APPEND CMAKE_MODULE_PATH "${COWL_DOCS_DIR}/cmake")
get_target_property(ULIB_DIRS ulib INTERFACE_INCLUDE_DIRECTORIES)
set(ULIB_PUBLIC_HEADERS_DIR "${COWL_ULIB_DIR}/include")
file(GLOB ULIB_PUBLIC_HEADERS CONFIGURE_DEPENDS "${ULIB_PUBLIC_HEADERS_DIR}/*.h")

# Doxygen configuration

Expand All @@ -33,8 +32,8 @@ set(DOXYGEN_PREDEFINED ${COWL_PUBLIC_DEFINES}
"COWL_RETAINED=/** @note You must release the returned object via <tt>#cowl_release()</tt>. */"
"COWL_DEPRECATED(msg)=/** @@deprecated msg */"
"COWL_INLINE=")
set(DOXYGEN_INCLUDE_PATH ${COWL_PUBLIC_HEADERS_DIRS} ${ULIB_DIRS})
set(DOXYGEN_OUTPUT_DIRECTORY "${DOCS_OUTPUT_DIRECTORY}/doxygen")
set(DOXYGEN_INCLUDE_PATH ${COWL_PUBLIC_HEADERS_DIRS} ${ULIB_PUBLIC_HEADERS_DIR})
set(DOXYGEN_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen")
set(DOXYGEN_XML_OUTPUT_DIRECTORY "${DOXYGEN_OUTPUT_DIRECTORY}/xml")
set(DOXYGEN_ALIASES
[[destructor{1}="@note The returned object must be destroyed by calling <tt>#\1()</tt>."]]
Expand All @@ -48,12 +47,12 @@ set(DOXYGEN_ALIASES
)
set(DOXYGEN_VERBATIM_VARS DOXYGEN_ALIASES)

find_program(PYTHON
find_program(DOXYGEN_PYTHON
NAMES python3 python
DOC "Path to the Python interpreter")
DOC "Path to the Python interpreter used to run Doxygen input filters")

if(NOT PYTHON STREQUAL "PYTHON-NOTFOUND")
set(DOXYGEN_INPUT_FILTER "${PYTHON} ${DOXYGEN_UTILS_DIRECTORY}/alias.py")
if(DOXYGEN_PYTHON)
set(DOXYGEN_INPUT_FILTER "${DOXYGEN_PYTHON} ${COWL_ULIB_UTILS_DIR}/doxygen/alias.py")
endif()

# Documentation targets
Expand All @@ -70,12 +69,12 @@ if(DOXYGEN_FOUND)

set(DOXYGEN_TARGET_NAME cowl-doxygen)
sphinx_add_docs("${DOCS_TARGET_NAME}" "${SPHINX_INPUT_DIRECTORY}" ARGS -W
COMMENT "Generate documentation via Sphinx")
COMMENT "Generating documentation via Sphinx")
add_dependencies("${DOCS_TARGET_NAME}" "${DOXYGEN_TARGET_NAME}" ulib-docs)
else()
set(DOXYGEN_TARGET_NAME "${DOCS_TARGET_NAME}")
endif()

doxygen_add_docs("${DOXYGEN_TARGET_NAME}" ${COWL_PUBLIC_HEADERS}
COMMENT "Generate documentation via Doxygen")
doxygen_add_docs("${DOXYGEN_TARGET_NAME}" ${COWL_PUBLIC_HEADERS} ${ULIB_PUBLIC_HEADERS}
COMMENT "Generating documentation via Doxygen")
endif()
31 changes: 0 additions & 31 deletions docs/cmake/FindSphinx.cmake

This file was deleted.

Loading

0 comments on commit e44df2d

Please sign in to comment.