Skip to content

Commit 0458f28

Browse files
committed
build: extend fmt integration options
1 parent a31ae91 commit 0458f28

File tree

3 files changed

+113
-32
lines changed

3 files changed

+113
-32
lines changed

.github/workflows/ci.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ jobs:
3737
msvc 14.34
3838
standards: '>=20'
3939
max-standards: 1
40-
latest-factors: gcc
41-
factors: clang # Don't include Asan because `clang/AST/Decl.h` fails
40+
latest-factors: ''
41+
factors: |
42+
gcc Fetch-Content
43+
trace-commands: true
4244

4345
build:
4446
needs: cpp-matrix
@@ -92,7 +94,7 @@ jobs:
9294
id: package-install
9395
with:
9496
apt-get: ${{ matrix.install }} openjdk-11-jdk ninja-build
95-
vcpkg: fmt libxml2[tools]
97+
vcpkg: ${{ ( !matrix.fetch-content && 'fmt' ) || '' }} libxml2[tools]
9698
cc: ${{ steps.setup-cpp.outputs.cc || matrix.cc }}
9799
ccflags: ${{ matrix.ccflags }}
98100
cxx: ${{ steps.setup-cpp.outputs.cxx || matrix.cxx }}

CMakeLists.txt

+65-28
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,65 @@ add_definitions(${LLVM_DEFINITIONS})
8585
llvm_map_components_to_libnames(llvm_libs all)
8686

8787
# Duktape
88-
if(NOT DEFINED DUKTAPE_SOURCE_ROOT)
89-
set(DUKTAPE_SOURCE_ROOT $ENV{DUKTAPE_SOURCE_ROOT})
90-
endif()
91-
if (NOT DUKTAPE_SOURCE_ROOT)
92-
include(FetchContent)
93-
if (POLICY CMP0135)
94-
cmake_policy(SET CMP0135 NEW)
95-
endif()
96-
FetchContent_Declare(
97-
duktape
98-
URL https://github.com/svaarala/duktape/releases/download/v2.7.0/duktape-2.7.0.tar.xz
99-
)
100-
FetchContent_GetProperties(duktape)
101-
if(NOT duktape_POPULATED)
102-
FetchContent_Populate(duktape)
103-
set(DUKTAPE_SOURCE_ROOT ${duktape_SOURCE_DIR})
88+
find_package(duktape CONFIG)
89+
if (duktape_FOUND)
90+
if (NOT TARGET duktape::duktape)
91+
add_library(duktape INTERFACE)
92+
target_link_libraries(duktape main ${DUKTAPE_LIBRARY})
93+
target_include_directories(duktape INTERFACE ${DUKTAPE_INCLUDE_DIRS})
94+
target_include_directories(duktape PUBLIC ${DUKTAPE_SOURCE_ROOT}/src)
95+
add_library(duktape::duktape ALIAS duktape)
10496
endif()
105-
endif()
106-
add_library(duktape ${DUKTAPE_SOURCE_ROOT}/src/duktape.c ${DUKTAPE_SOURCE_ROOT}/src/duktape.h)
107-
target_include_directories(duktape PUBLIC ${DUKTAPE_SOURCE_ROOT}/src)
108-
add_library(duktape::duktape ALIAS duktape)
109-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
110-
target_compile_options(duktape PRIVATE -w)
111-
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
112-
target_compile_options(duktape PRIVATE /w)
113-
endif()
97+
else()
98+
if (NOT DEFINED DUKTAPE_SOURCE_ROOT)
99+
set(DUKTAPE_SOURCE_ROOT $ENV{DUKTAPE_SOURCE_ROOT})
100+
endif ()
101+
if (NOT DUKTAPE_SOURCE_ROOT)
102+
include(FetchContent)
103+
if (POLICY CMP0135)
104+
cmake_policy(SET CMP0135 NEW)
105+
endif ()
106+
FetchContent_Declare(
107+
duktape
108+
URL https://github.com/svaarala/duktape/releases/download/v2.7.0/duktape-2.7.0.tar.xz
109+
)
110+
FetchContent_GetProperties(duktape)
111+
if (NOT duktape_POPULATED)
112+
FetchContent_Populate(duktape)
113+
set(DUKTAPE_SOURCE_ROOT ${duktape_SOURCE_DIR})
114+
endif ()
115+
endif ()
116+
add_library(duktape ${DUKTAPE_SOURCE_ROOT}/src/duktape.c ${DUKTAPE_SOURCE_ROOT}/src/duktape.h)
117+
target_include_directories(duktape PUBLIC ${DUKTAPE_SOURCE_ROOT}/src)
118+
add_library(duktape::duktape ALIAS duktape)
119+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
120+
target_compile_options(duktape PRIVATE -w)
121+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
122+
target_compile_options(duktape PRIVATE /w)
123+
endif ()
124+
endif ()
114125

115126
# fmt
116-
unset(CMAKE_FOLDER)
117-
find_package(fmt REQUIRED CONFIG)
127+
find_package(fmt CONFIG)
128+
if (NOT fmt_FOUND)
129+
if (NOT DEFINED FMT_SOURCE_ROOT)
130+
set(FMT_SOURCE_ROOT $ENV{FMT_SOURCE_ROOT})
131+
endif ()
132+
if (NOT FMT_SOURCE_ROOT)
133+
include(FetchContent)
134+
FetchContent_Declare(
135+
fmt
136+
URL https://github.com/fmtlib/fmt/releases/download/10.0.0/fmt-10.0.0.zip
137+
)
138+
FetchContent_GetProperties(fmt)
139+
if (NOT fmt_POPULATED)
140+
FetchContent_Populate(fmt)
141+
set(FMT_SOURCE_ROOT ${fmt_SOURCE_DIR})
142+
endif ()
143+
endif ()
144+
endif ()
145+
146+
unset(CMAKE_FOLDER) # Dependencies
118147

119148
#-------------------------------------------------
120149
#
@@ -164,8 +193,16 @@ else()
164193
endif()
165194
target_include_directories(mrdox SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
166195

196+
# duktape
197+
target_link_libraries(mrdox PRIVATE duktape::duktape)
198+
167199
# fmt
168-
target_link_libraries(mrdox PUBLIC fmt::fmt duktape::duktape)
200+
if (fmt_FOUND)
201+
target_link_libraries(mrdox PRIVATE fmt::fmt)
202+
else ()
203+
target_include_directories(mrdox SYSTEM PRIVATE ${FMT_SOURCE_ROOT}/include)
204+
target_compile_definitions(mrdox PRIVATE FMT_HEADER_ONLY)
205+
endif()
169206

170207
# Windows, Win64
171208
if (WIN32)

docs/modules/ROOT/pages/install.adoc

+43-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Binaries are available from our https://github.com/cppalliance/mrdox/releases[Re
88

99
=== Requirements
1010

11+
==== LLVM
12+
1113
MrDox depends on a recent version of LLVM.
1214

1315
Here are the instructions to clone LLVM version required by this project.
@@ -44,9 +46,49 @@ cmake --build . -j <threads>
4446
cmake --install .
4547
----
4648

49+
==== fmt
50+
51+
MrDox uses the `fmt` library to format its messages. The library can be downloaded from https://vcpkg.io/en/getting-started.html[vcpkg] or installed from https://github.com/fmtlib/fmt[their official repository].
52+
53+
When using vcpkg, its toolchain should be provided to the mrdox cmake configure command:
54+
55+
[source,bash]
56+
----
57+
cmake -B [build directory] -S [path to mrdox] -D CMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake
58+
----
59+
60+
When the `fmt` library has been installed from their official release, the library path should be provided to the mrdox cmake configure command:
61+
62+
[source,bash]
63+
----
64+
cmake -B [build directory] -S [path to mrdox] -D FMT_ROOT=[path to installed fmt]
65+
----
66+
67+
Alternatively, when neither option is available, the mrdox configure script will attempt to automatically download the `fmt` library during configuration.
68+
69+
==== duktape
70+
71+
The MrDox templating system uses the duktape JS interpreter for its handlebars templating system. The library can be downloaded from https://vcpkg.io/en/getting-started.html[vcpkg] or installed from https://duktape.org/[their official repository].
72+
73+
When using vcpkg, its toolchain should be provided to the mrdox cmake configure command:
74+
75+
[source,bash]
76+
----
77+
cmake -B [build directory] -S [path to mrdox] -D CMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake
78+
----
79+
80+
When duktape has been installed from their https://github.com/svaarala/duktape/releases/tag/v2.7.0[official release], the duktape source path should be provided to the mrdox cmake configure command:
81+
82+
[source,bash]
83+
----
84+
cmake -B [build directory] -S [path to mrdox] -D DUKTAPE_SOURCE_ROOT=[path to duktape source]
85+
----
86+
87+
Alternatively, when neither option is available, the mrdox configure script will attempt to automatically download duktape during configuration.
88+
4789
=== MrDox
4890

49-
Once the LLVM variants are available in `/path/to/llvm+clang`, you can download MrDox:
91+
Once the LLVM variants and dependencies are available in `/path/to/llvm+clang`, you can download MrDox:
5092

5193
[source,bash]
5294
----

0 commit comments

Comments
 (0)