Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.git/
.idea/
.vs/
.git
.idea
.vs

cmake-build-*

documentation/.doxygen/css
documentation/.doxygen/html
documentation/.doxygen/latex
41 changes: 17 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ project(cae

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")

option(CAE_BUILD_DOC_HTML "Build html documentation" OFF)
option(CAE_BUILD_DOC_PDF "Build pdf documentation" OFF)
option(CAE_CLANG_FORMAT "Enable clang-format" OFF)
option(CAE_CLANG_TIDY "Enable clang-tidy static analysis" OFF)

file(GLOB_RECURSE PROJECT_FILES
${SOURCES}
Expand All @@ -21,6 +24,8 @@ file(GLOB_RECURSE PROJECT_FILES
"${PROJECT_SOURCE_DIR}/plugins/*.hpp"
)

include(FetchContent)

include(MakeVersion)
include(MakeDoc)
include(ClangTidy)
Expand All @@ -30,32 +35,20 @@ include(CompileOptions)

if (CAE_CLANG_FORMAT)
format_project(${PROJECT_FILES})
endif()
endif ()

find_package(nlohmann_json QUIET CONFIG)
if (NOT nlohmann_json_FOUND)
include(FetchContent)
FetchContent_Declare(
nlohmann-json
GIT_REPOSITORY "https://github.com/nlohmann/json.git"
GIT_TAG "v3.12.0"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(nlohmann-json)
if (CAE_CLANG_TIDY)
run_clang_tidy(${PROJECT_FILES})
endif ()
find_package(glm QUIET CONFIG)
if (NOT glm_FOUND)
FetchContent_Declare(
glm
GIT_REPOSITORY "https://github.com/g-truc/glm.git"
GIT_TAG 1.0.3
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
set(GLM_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(glm)

if (CAE_BUILD_DOC_HTML OR CAE_BUILD_DOC_PDF)
find_package(Doxygen REQUIRED)
cae_download_extra_css()
if (CAE_BUILD_DOC_HTML)
cae_add_doxygen_html(cae-doc-html ${PROJECT_FILES})
elseif (CAE_BUILD_DOC_PDF)
cae_add_doxygen_pdf(cae-doc-pdf ${PROJECT_FILES})
endif ()
endif ()

add_subdirectory(modules)
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ This section targets engine developers and contributors.

### CMake Build options

- `CAE_STRICT_WARNINGS` (default: `OFF`): Enable strict warning level.
- `CAE_ENABLE_SANITIZERS` (default: `OFF`): Enable address and undefined sanitizers.
- `CAE_ENABLE_LTO` (default: `OFF`): Enable LTO on final targets.
- `CAE_BUILD_DOC_HTML` (default: `OFF`): Enable building doxygen html documentation.
- `CAE_BUILD_DOC_PDF` (default: `OFF`): Enable building doxygen pdf documentation.
- `CAE_BUILD_TESTS` (default: `OFF`): Enable building unit tests.
- `CAE_CLANG_TIDY` (default: `OFF`): Enable clang tidy usage.
- `CAE_CLANG_FORMAT` (default: `OFF`): Enable clang format usage.
- `CAE_BUILD_DOC` (default: `OFF`): Enable building doxygen documentation.
- `CAE_CLANG_TIDY` (default: `OFF`): Enable clang tidy usage.
- `CAE_ENABLE_LTO` (default: `OFF`): Enable LTO on final targets.
- `CAE_ENABLE_SANITIZERS` (default: `OFF`): Enable address and undefined sanitizers.
- `CAE_STRICT_WARNINGS` (default: `OFF`): Enable strict warning level.

### Preprocessor macros

Expand Down Expand Up @@ -109,7 +110,7 @@ Use the `CAE_BUILD_TESTS` option.

documentation is generated using [Doxygen](https://www.doxygen.nl/).

Use the `CAE_BUILD_DOC` option.
Use the `CAE_BUILD_DOC_HTML` or/and `CAE_BUILD_DOC_PDF` option.

## Third-party libraries

Expand Down
22 changes: 20 additions & 2 deletions apps/Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ project(cae-editor

generate_version_header("${CMAKE_BINARY_DIR}/include/CAE/VersionEditor.hpp")

find_package(nlohmann_json QUIET CONFIG)
if (NOT nlohmann_json_FOUND)
FetchContent_Declare(
nlohmann-json
GIT_REPOSITORY "https://github.com/nlohmann/json.git"
GIT_TAG "v3.12.0"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(nlohmann-json)
endif ()

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.cpp")

add_executable(${PROJECT_NAME} ${SOURCES})

if (CAE_ENABLE_LTO)
cae_enable_lto(${PROJECT_NAME})
endif ()

target_compile_definitions(${PROJECT_NAME} PRIVATE PLUGINS_DIR="${CMAKE_BINARY_DIR}/bin/lib")

target_include_directories(${PROJECT_NAME} PRIVATE
Expand All @@ -19,9 +35,11 @@ target_include_directories(${PROJECT_NAME} PRIVATE
${glm_SOURCE_DIR}
)
target_link_libraries(${PROJECT_NAME} PRIVATE
cae-modules
cae-compile-options
cae-interfaces
cae-utils
cae-engine
nlohmann_json::nlohmann_json
glm::glm
)

set_target_properties(${PROJECT_NAME} PROPERTIES
Expand Down
6 changes: 2 additions & 4 deletions cmake/modules/ClangFormat.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
function(format_project FILES_TO_FORMAT)

find_program(CLANG_FORMAT_EXE NAMES clang-format REQUIRED)

add_custom_target(${PROJECT_NAME}-clang-format
add_custom_target("${PROJECT_NAME}-clang-format"
COMMAND ${CLANG_FORMAT_EXE} -style=file -i ${FILES_TO_FORMAT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Formatting sources with clang-format"
)
add_custom_target(${PROJECT_NAME}-clang-format-check
add_custom_target("${PROJECT_NAME}-clang-format-check"
COMMAND ${CLANG_FORMAT_EXE} --dry-run --Werror -style=file ${FILES_TO_FORMAT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Checking source formatting"
)

endfunction()
15 changes: 5 additions & 10 deletions cmake/modules/ClangTidy.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
option(CAE_CLANG_TIDY "Enable clang-tidy static analysis" OFF)

if (NOT CAE_CLANG_TIDY)
return()
endif()

find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)

set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-header-filter=${CMAKE_SOURCE_DIR}/src")
set_source_files_properties(${SOURCES} PROPERTIES CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY}")
function(run_clang_tidy FILES)
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-header-filter=${CMAKE_SOURCE_DIR}/src")
set_source_files_properties(${FILES} PROPERTIES CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY}")
endfunction()
34 changes: 18 additions & 16 deletions cmake/modules/CompileOptions.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
add_library(cae-compile-options INTERFACE)
set(TARGET_NAME "cae-compile-options")

target_compile_features(cae-compile-options INTERFACE cxx_std_23)
add_library(${TARGET_NAME} INTERFACE)

target_compile_features(${TARGET_NAME} INTERFACE cxx_std_23)

option(CAE_STRICT_WARNINGS "Enable strict warning level" OFF)
option(CAE_ENABLE_SANITIZERS "Enable address and undefined sanitizers" OFF)
option(CAE_ENABLE_LTO "Enable LTO on final targets" OFF)

target_compile_options(cae-compile-options INTERFACE
target_compile_options(${TARGET_NAME} INTERFACE
# Strict warnings
$<$<AND:$<CXX_COMPILER_ID:GNU,Clang,AppleClang>,$<BOOL:${CAE_STRICT_WARNINGS}>,$<NOT:$<PLATFORM_ID:Android,Emscripten,iOS>>>:
-Wall
Expand Down Expand Up @@ -45,68 +47,68 @@ target_compile_options(cae-compile-options INTERFACE
)

# GCC / Clang
target_compile_options(cae-compile-options INTERFACE
target_compile_options(${TARGET_NAME} INTERFACE
$<$<AND:$<CONFIG:RelWithDebInfo>,$<CXX_COMPILER_ID:GNU,Clang,AppleClang>>:-O2>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU,Clang,AppleClang>>:-O0 -g>
)

# MSVC
target_compile_options(cae-compile-options INTERFACE
target_compile_options(${TARGET_NAME} INTERFACE
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2>
$<$<AND:$<CONFIG:RelWithDebInfo>,$<CXX_COMPILER_ID:MSVC>>:/O2 /Zi>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Od /Zi>
)

target_compile_definitions(cae-compile-options INTERFACE
target_compile_definitions(${TARGET_NAME} INTERFACE
$<$<CONFIG:Debug>:
CAE_DEBUG
>
)

if(CAE_ENABLE_SANITIZERS)
target_compile_options(cae-compile-options INTERFACE
target_compile_options(${TARGET_NAME} INTERFACE
$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<NOT:$<PLATFORM_ID:Android,Emscripten,Windows>>>:
-fsanitize=address,undefined
>
)
target_link_options(cae-compile-options INTERFACE
target_link_options(${TARGET_NAME} INTERFACE
$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<NOT:$<PLATFORM_ID:Android,Emscripten,Windows>>>:
-fsanitize=address,undefined
>
)
endif()

function(cae_enable_lto target)
function(cae_enable_lto TARGET)
if (CAE_ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT CAE_LTO_SUPPORTED OUTPUT CAE_LTO_ERROR)
if (CAE_LTO_SUPPORTED)
set_property(TARGET ${target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
set_property(TARGET ${TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "CAE: LTO not supported: ${CAE_LTO_ERROR}")
endif()
endif()
endfunction()

if (EMSCRIPTEN)
target_compile_definitions(cae-compile-options INTERFACE
target_compile_definitions(${TARGET_NAME} INTERFACE
CAE_PLATFORM_WEB
)
elseif (ANDROID)
target_compile_definitions(cae-compile-options INTERFACE CAE_PLATFORM_ANDROID)
target_compile_definitions(${TARGET_NAME} INTERFACE CAE_PLATFORM_ANDROID)
elseif (APPLE)
if (IOS)
target_compile_definitions(cae-compile-options INTERFACE CAE_PLATFORM_IOS)
target_compile_definitions(${TARGET_NAME} INTERFACE CAE_PLATFORM_IOS)
else()
target_compile_definitions(cae-compile-options INTERFACE CAE_PLATFORM_MACOS)
target_compile_definitions(${TARGET_NAME} INTERFACE CAE_PLATFORM_MACOS)
endif()
elseif (WIN32)
target_compile_definitions(cae-compile-options INTERFACE
target_compile_definitions(${TARGET_NAME} INTERFACE
CAE_PLATFORM_WINDOWS
NOMINMAX
WIN32_LEAN_AND_MEAN
)
elseif (UNIX)
target_compile_definitions(cae-compile-options INTERFACE CAE_PLATFORM_LINUX)
target_compile_definitions(${TARGET_NAME} INTERFACE CAE_PLATFORM_LINUX)
endif()

2 changes: 1 addition & 1 deletion cmake/modules/CopyAssets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function(copy_directory_to_target TARGET SRC_DIR DST_SUBDIR)
message(FATAL_ERROR "Target '${TARGET}' does not exist")
endif()

set(COPY_TARGET_NAME ${TARGET}-copy-assets)
set(COPY_TARGET_NAME "${TARGET}-copy-assets")

set(DST_DIR "$<TARGET_FILE_DIR:${TARGET}>/${DST_SUBDIR}")

Expand Down
54 changes: 29 additions & 25 deletions cmake/modules/MakeDoc.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
option(CAE_BUILD_DOC "Build documentation" OFF)
include_guard(GLOBAL)

if (NOT CAE_BUILD_DOC)
return()
endif()
set(DOXYGEN_DIR "${CMAKE_SOURCE_DIR}/documentation/.doxygen")
set(DOXYFILE_OUT "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")

find_package(Doxygen REQUIRED)
function(cae_download_extra_css)
file(DOWNLOAD "https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/v2.4.1/doxygen-awesome.css"
"${DOXYGEN_DIR}/css/doxygen-awesome.css")
file(DOWNLOAD "https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/v2.4.1/doxygen-awesome-sidebar-only.css"
"${DOXYGEN_DIR}/css/doxygen-awesome-sidebar-only.css")
endfunction()

file(DOWNLOAD https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/v2.4.1/doxygen-awesome.css
${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome.css)
file(DOWNLOAD https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/v2.4.1/doxygen-awesome-sidebar-only.css
${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome-sidebar-only.css)
function(cae_add_doxygen_html TARGET FILES)
configure_file("${DOXYGEN_DIR}/Doxyfile" ${DOXYFILE_OUT} @ONLY)
doxygen_add_docs(${TARGET} ${FILES})
add_custom_command(TARGET ${TARGET} POST_BUILD
WORKING_DIRECTORY ${DOXYGEN_DIR}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
VERBATIM
)
endfunction()

set(DOXYGEN_DIR "${CMAKE_SOURCE_DIR}/documentation/.doxygen")
set(DOXYFILE_OUT "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
configure_file("${DOXYGEN_DIR}/Doxyfile" ${DOXYFILE_OUT} @ONLY)
doxygen_add_docs(doxygen ${PROJECT_FILES})
add_custom_command(TARGET doxygen POST_BUILD
WORKING_DIRECTORY ${DOXYGEN_DIR}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
VERBATIM
)
add_custom_command(TARGET doxygen POST_BUILD
WORKING_DIRECTORY "${DOXYGEN_DIR}/latex"
COMMAND make > /dev/null
COMMAND ${CMAKE_COMMAND} -E copy "refman.pdf" "${CMAKE_SOURCE_DIR}/documentation/${PROJECT_NAME}.pdf"
BYPRODUCTS "${CMAKE_SOURCE_DIR}/documentation/${PROJECT_NAME}.pdf"
VERBATIM
)
function(cae_add_doxygen_pdf TARGET FILES)
configure_file("${DOXYGEN_DIR}/Doxyfile" ${DOXYFILE_OUT} @ONLY)
doxygen_add_docs(${TARGET} ${FILES})
add_custom_command(TARGET ${TARGET} POST_BUILD
WORKING_DIRECTORY "${DOXYGEN_DIR}/latex"
COMMAND make > /dev/null
COMMAND ${CMAKE_COMMAND} -E copy "refman.pdf" "${CMAKE_SOURCE_DIR}/documentation/${PROJECT_NAME}.pdf"
BYPRODUCTS "${CMAKE_SOURCE_DIR}/documentation/${PROJECT_NAME}.pdf"
VERBATIM
)
endfunction()
Loading