Skip to content

Commit 944892f

Browse files
committed
Add find cmake script and fix README.md
1 parent 775ecf1 commit 944892f

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,71 @@ Compilation of Jinja2Cpp tested on the following compilers (with C++14 enabled f
142142
- Linux clang 5.0
143143
- Microsoft Visual Studio 2015 x86
144144
- Microsoft Visual Studio 2017 x86
145+
146+
# Build and install
147+
Jinja2Cpp has got only one external dependency: boost library (at least version 1.55). Because of types from boost are used inside library, you should compile both your projects and Jinja2Cpp library with similar compiler settings. Otherwise ABI could be broken.
148+
149+
In order to compile Jinja2Cpp you need:
150+
151+
1. Install CMake build system (at least version 3.0)
152+
2. Clone jinja2cpp repository and update submodules:
153+
154+
```
155+
> git clone https://github.com/flexferrum/Jinja2Cpp.git
156+
> git submodule -q update --init
157+
```
158+
159+
3. Create build directory:
160+
161+
```
162+
> cd Jinja2Cpp
163+
> mkdir build
164+
```
165+
166+
4. Run CMake and build the library:
167+
168+
```
169+
> cd build
170+
> cmake .. -DCMAKE_INSTALL_PREFIX=<path to install folder>
171+
> cmake --build . --target all
172+
```
173+
"Path to install folder" here is a path to the folder where you want to install Jinja2Cpp lib.
174+
175+
5. Install library:
176+
177+
```
178+
> cmake --build . --target install
179+
```
180+
181+
6. Also you can run the tests:
182+
183+
```
184+
> ctest -C Release
185+
```
186+
187+
# Link with you projects
188+
Jinja2Cpp is shipped with cmake finder script. So you can:
189+
190+
1. Include Jinja2Cpp cmake scripts to the project:
191+
```cmake
192+
list (APPEND CMAKE_MODULE_PATH ${JINJA2CPP_INSTALL_DIR}/cmake)
193+
```
194+
195+
2. Use regular 'find' script:
196+
```cmake
197+
find_package(Jinja2Cpp)
198+
```
199+
200+
3. Add found paths to the project settings:
201+
```cmake
202+
#...
203+
include_directories(
204+
${JINJA2CPP_INCLUDE_DIR}
205+
)
206+
207+
target_link_libraries(YourTarget
208+
${JINJA2CPP_LIBRARY}
209+
)
210+
#...
211+
```
212+

cmake/public/FindJinja2Cpp.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function (_Jinja2Cpp_Find_Library varName)
2+
find_library(${varName}
3+
NAMES ${ARGN}
4+
HINTS
5+
ENV JINJA2CPP_ROOT
6+
${JINJA2CPP_INSTALL_DIR}
7+
PATH_SUFFIXES lib/static lib64/static
8+
)
9+
mark_as_advanced(${varName})
10+
endfunction ()
11+
12+
find_path(JINJA2CPP_INCLUDE_DIR jinja2cpp/template.h
13+
HINTS
14+
$ENV{JINJA2CPP_ROOT}/include
15+
${JINJA2CPP_INSTALL_DIR}/include
16+
)
17+
mark_as_advanced(${JINJA2CPP_INCLUDE_DIR})
18+
19+
_Jinja2Cpp_Find_Library(JINJA2CPP_LIBRARY jinja2cpp)
20+
21+
include(FindPackageHandleStandardArgs)
22+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(JINJA2CPP DEFAULT_MSG JINJA2CPP_LIBRARY JINJA2CPP_INCLUDE_DIR)

0 commit comments

Comments
 (0)