2023-04-30 22:45:37 +02:00
cmake_minimum_required ( VERSION 3.15 )
2021-12-22 14:13:29 +01:00
2023-05-08 18:45:42 +02:00
set ( git_version 156 ) # Obtained with `git rev-list --count HEAD`
2021-12-22 14:13:29 +01:00
project ( Diagon
LANGUAGES C CXX
2023-05-08 18:45:42 +02:00
VERSION 1.1. ${ git_version }
2021-12-22 14:13:29 +01:00
)
2018-01-20 09:47:42 +01:00
2022-11-20 14:40:43 +01:00
option ( DIAGON_BUILD_TESTS "Set to ON to build tests" OFF )
2022-11-20 11:32:02 +01:00
option ( DIAGON_BUILD_TESTS_FUZZER "Set to ON to enable fuzzing" OFF )
2023-05-04 23:33:48 +02:00
option ( DIAGON_ASAN "Set to ON to enable address sanitizer" OFF )
option ( DIAGON_LSAN "Set to ON to enable leak sanitizer" OFF )
option ( DIAGON_MSAN "Set to ON to enable memory sanitizer" OFF )
option ( DIAGON_TSAN "Set to ON to enable thread sanitizer" OFF )
option ( DIAGON_UBSAN "Set to ON to enable undefined behavior sanitizer" OFF )
2022-11-20 11:32:02 +01:00
2020-12-20 23:12:31 +01:00
include ( FetchContent )
2021-12-22 14:13:29 +01:00
set ( FETCHCONTENT_QUIET FALSE )
2018-01-20 09:47:42 +01:00
2021-03-15 00:41:30 +01:00
#-------------------------------------------------------------------------------
FetchContent_Declare ( json
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
2021-12-22 14:13:29 +01:00
GIT_TAG v3.9.1
GIT_PROGRESS TRUE
)
2021-03-15 00:41:30 +01:00
FetchContent_GetProperties ( json )
if ( NOT json_POPULATED )
FetchContent_Populate ( json )
add_subdirectory ( ${ json_SOURCE_DIR } ${ json_BINARY_DIR } EXCLUDE_FROM_ALL )
endif ( )
#-------------------------------------------------------------------------------
FetchContent_Declare ( antlr
2023-05-13 18:54:06 +02:00
#GIT_REPOSITORY https://github.com/antlr/antlr4
GIT_REPOSITORY https://github.com/ArthurSonzogni/antlr4
# GIT_TAG 1cb4669f84cea5b59661fd44b0f80509fdacd3f9
GIT_TAG remove-pthread
2023-01-22 16:26:36 +01:00
GIT_SHALLOW FALSE
2021-12-22 14:13:29 +01:00
GIT_PROGRESS TRUE
)
2021-03-15 00:41:30 +01:00
FetchContent_GetProperties ( antlr )
if ( NOT antlr_POPULATED )
FetchContent_Populate ( antlr )
SET ( WITH_LIBCXX OFF CACHE BOOL "" )
2021-03-16 21:27:31 +01:00
SET ( CMAKE_HOME_DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR } )
2021-03-15 00:41:30 +01:00
add_subdirectory (
${ antlr_SOURCE_DIR } /runtime/Cpp
${ antlr_BINARY_DIR }
EXCLUDE_FROM_ALL )
target_include_directories ( antlr4_static
PUBLIC ${ antlr_SOURCE_DIR } /runtime/Cpp/runtime/src
)
endif ( )
#-------------------------------------------------------------------------------
2021-03-19 01:16:50 +01:00
if ( MSVC )
add_compile_options ( "/utf-8" )
endif ( )
2020-12-20 23:12:31 +01:00
add_subdirectory ( ${ CMAKE_CURRENT_SOURCE_DIR } /tools )
2018-01-20 09:47:42 +01:00
2020-05-17 14:07:23 +02:00
function ( target_set_common target )
2021-12-22 14:13:29 +01:00
set_target_properties ( ${ target } PROPERTIES
VERSION ${ PROJECT_VERSION }
CXX_STANDARD 17
)
2020-12-20 23:12:31 +01:00
if ( EMSCRIPTEN )
2022-12-19 19:48:38 +01:00
target_compile_options ( ${ target } PRIVATE "-fwasm-exceptions" )
target_link_options ( ${ target } PRIVATE "-fwasm-exceptions" )
2020-05-17 14:26:43 +02:00
# Nothing
elseif ( MSVC )
2023-05-04 23:38:29 +02:00
set_property ( TARGET ${ target } PROPERTY
2023-04-30 23:09:46 +02:00
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
2020-05-17 13:18:03 +02:00
target_compile_options ( ${ target } PRIVATE "/wd4244" )
target_compile_options ( ${ target } PRIVATE "/wd4267" )
target_compile_options ( ${ target } PRIVATE "/wd4996" )
target_compile_options ( ${ target } PRIVATE "/wd4305" )
else ( )
target_compile_options ( ${ target } PRIVATE "-Wall" )
target_compile_options ( ${ target } PRIVATE "-Wno-sign-compare" )
target_compile_options ( ${ target } PRIVATE "-Wno-attributes" )
endif ( )
endfunction ( )
2020-12-21 00:40:04 +01:00
set ( test_directory ${ CMAKE_CURRENT_SOURCE_DIR } /test )
2020-12-20 23:12:31 +01:00
# Include source files and the generated files
include_directories ( ${ CMAKE_CURRENT_BINARY_DIR } /src )
include_directories ( ${ CMAKE_CURRENT_SOURCE_DIR } /src )
2018-01-20 09:47:42 +01:00
2020-12-20 23:12:31 +01:00
#-------------------------------------------------------------------------------
# Environment variable available in C++ source
2020-06-20 18:35:24 +02:00
#-------------------------------------------------------------------------------
2020-12-20 23:12:31 +01:00
configure_file (
${ CMAKE_CURRENT_SOURCE_DIR } /src/environment.h.in
${ CMAKE_CURRENT_BINARY_DIR } /src/environment.h
)
#-------------------------------------------------------------------------------
add_library ( diagon_base STATIC
src/translator/Translator.cpp
src/translator/Translator.h
2022-05-08 08:35:11 +02:00
src/translator/antlr_error_listener.cpp
src/translator/antlr_error_listener.h
)
target_link_libraries ( diagon_base
PRIVATE antlr4_static
2020-12-20 23:12:31 +01:00
)
2021-06-09 20:57:15 +02:00
target_set_common ( diagon_base )
2020-12-20 23:12:31 +01:00
2022-12-04 10:54:32 +01:00
set ( Boost_USE_STATIC_LIBS ON )
2020-12-20 23:12:31 +01:00
add_subdirectory ( src/screen )
add_subdirectory ( src/translator/frame )
add_subdirectory ( src/translator/grammar )
add_subdirectory ( src/translator/graph_dag )
add_subdirectory ( src/translator/graph_planar )
add_subdirectory ( src/translator/math )
2020-12-21 00:40:04 +01:00
add_subdirectory ( src/translator/flowchart )
2020-12-20 23:12:31 +01:00
add_subdirectory ( src/translator/sequence )
add_subdirectory ( src/translator/table )
add_subdirectory ( src/translator/tree )
add_library ( diagon_lib STATIC
2021-03-15 00:41:30 +01:00
src/api.cpp
src/api.hpp
2020-12-20 23:12:31 +01:00
src/translator/Factory.cpp
src/translator/Factory.h
)
2021-06-09 20:57:15 +02:00
target_set_common ( diagon_lib )
2020-12-20 23:12:31 +01:00
target_link_libraries ( diagon_lib
PRIVATE diagon_base
PRIVATE translator_frame
PRIVATE translator_grammar
PRIVATE translator_graph_dag
PRIVATE translator_graph_planar
PRIVATE translator_math
2020-12-21 00:40:04 +01:00
PRIVATE translator_flowchart
2020-12-20 23:12:31 +01:00
PRIVATE translator_sequence
PRIVATE translator_table
PRIVATE translator_tree
PRIVATE antlr4_static
PRIVATE screen
2021-03-15 00:41:30 +01:00
PRIVATE nlohmann_json::nlohmann_json
2020-12-20 23:12:31 +01:00
)
target_set_common ( diagon_lib )
2021-03-15 00:41:30 +01:00
add_executable ( diagon src/main.cpp )
target_link_libraries ( diagon PRIVATE diagon_lib )
target_set_common ( diagon )
2020-12-20 23:12:31 +01:00
if ( EMSCRIPTEN )
# Emscripten options
string ( APPEND CMAKE_CXX_FLAGS " -Os" )
string ( APPEND CMAKE_CXX_FLAGS " -s WASM=1" )
string ( APPEND CMAKE_CXX_FLAGS " --closure 1" )
2021-03-15 00:41:30 +01:00
string ( APPEND CMAKE_CXX_FLAGS " -fexceptions" )
2022-03-20 15:40:14 +01:00
string ( APPEND CMAKE_CXX_FLAGS " -sUSE_BOOST_HEADERS" )
2021-03-15 00:41:30 +01:00
#string(APPEND CMAKE_CXX_FLAGS " -s STANDALONE_WASM")
#string(APPEND CMAKE_CXX_FLAGS " -s WASM_ASYNC_COMPILATION=0")
#string(APPEND CMAKE_CXX_FLAGS " -s SIDE_MODULE=1")
#string(APPEND CMAKE_CXX_FLAGS " -s DISABLE_EXCEPTION_CATCHING=0")
2022-12-19 19:48:38 +01:00
string ( APPEND CMAKE_CXX_FLAGS " -s EXPORTED_RUNTIME_METHODS='[\" ccall\ ",\" cwrap\ "]'" )
2020-12-20 23:12:31 +01:00
option ( ADD_GOOGLE_ANALYTICS "Build the static library" ON )
if ( ADD_GOOGLE_ANALYTICS )
file ( READ
2021-03-16 21:27:31 +01:00
${ CMAKE_CURRENT_SOURCE_DIR } /src/google-analytics.html
2020-12-20 23:12:31 +01:00
google-analytics )
endif ( ADD_GOOGLE_ANALYTICS )
foreach ( file
"style.css"
"index.html"
2021-03-20 19:04:38 +01:00
"run_diagon.sh" )
2020-12-20 23:12:31 +01:00
configure_file (
2021-03-16 21:27:31 +01:00
${ CMAKE_CURRENT_SOURCE_DIR } /src/ ${ file }
2020-12-20 23:12:31 +01:00
${ CMAKE_CURRENT_BINARY_DIR } / ${ file }
)
endforeach ( file )
2021-03-15 00:41:30 +01:00
#set_target_properties(diagon PROPERTIES SUFFIX ".wasm")
2020-12-20 23:12:31 +01:00
else ( )
install ( TARGETS diagon RUNTIME DESTINATION "bin" )
endif ( )
2021-12-22 14:13:29 +01:00
if ( UNIX AND NOT APPLE )
set ( CPACK_GENERATOR "DEB;External;RPM;STGZ;TBZ2;TGZ;TXZ;TZ;TZST;ZIP" )
elseif ( UNIX AND APPLE )
set ( CPACK_GENERATOR "DragNDrop;NuGet;TGZ;ZIP" )
elseif ( WIN32 )
set ( CPACK_GENERATOR "DEB;NuGet;TGZ;ZIP" )
else ( )
set ( CPACK_GENERATOR "ZIP" )
endif ( )
set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Generate beautiful ASCII art diagrams. Diagon is a collection of interactive generators. Math formulas, sequences diagrams, graph, border, ... This is written in C++, available online with WebAssembly." )
set ( CPACK_PACKAGE_HOMEPAGE_URL "https://arthursonzogni.com/Diagon/" )
2020-06-20 18:35:24 +02:00
set ( CPACK_PACKAGE_NAME "diagon" )
set ( CPACK_PACKAGE_VENDOR "Arthur Sonzogni" )
2021-12-22 14:13:29 +01:00
set ( CPACK_PACKAGE_VERSION ${ PROJECT_VERSION } )
set ( CPACK_PACKAGE_VERSION_MAJOR ${ PROJECT_VERSION_MAJOR } )
set ( CPACK_PACKAGE_VERSION_MINOR ${ PROJECT_VERSION_MINOR } )
set ( CPACK_PACKAGE_VERSION_PATCH ${ PROJECT_VERSION_PATCH } )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" )
2020-06-20 18:35:24 +02:00
set ( CPACK_DEBIAN_PACKAGE_DEPENDS " " )
set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://arthursonzogni.com/Diagon/" )
2021-12-22 14:13:29 +01:00
set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE_URL "https://github.com/ArthurSonzogni/FTXUI/" )
set ( CPACK_DEBIAN_PACKAGE_MAINTAINER "Arthur Sonzogni" )
set ( CPACK_DEBIAN_PACKAGE_VERSION ${ PROJECT_VERSION } )
set ( CPACK_RPM_PACKAGE_LICENSE MIT )
2020-06-20 18:35:24 +02:00
include ( CPack )
2022-11-20 11:32:02 +01:00
2022-11-20 14:40:43 +01:00
if ( DIAGON_BUILD_TESTS )
include ( cmake/diagon_test.cmake )
endif ( )
2022-11-20 11:32:02 +01:00
if ( DIAGON_BUILD_TESTS_FUZZER )
include ( cmake/diagon_fuzzer.cmake )
endif ( )