@@ -11,6 +11,8 @@ cmake_policy(SET CMP0135 NEW) # https://cmake.org/cmake/help/latest/policy/CMP01
1111
1212project (minja VERSION 1.0.0 LANGUAGES CXX )
1313
14+ add_library (minja INTERFACE )
15+
1416set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
1517
1618# Test if clang-tidy is available
3638 set (MINJA_FUZZTEST_ENABLED_DEFAULT ON )
3739 set (MINJA_USE_VENV_DEFAULT ON )
3840endif ()
41+ option (MINJA_TEST_ENABLED "minja: Build with test(python interpreter required)" ON )
42+ option (MINJA_EXAMPLE_ENABLED "minja: Build with example" ON )
3943option (MINJA_FUZZTEST_ENABLED "minja: fuzztests enabled" MINJA_FUZZTEST_ENABLED_DEFAULT )
4044option (MINJA_FUZZTEST_FUZZING_MODE "minja: run fuzztests (if enabled) in fuzzing mode" OFF )
4145option (MINJA_USE_VENV "minja: use Python venv for build" MINJA_USE_VENV_DEFAULT )
@@ -53,15 +57,20 @@ include(FetchContent)
5357# Fetch nlohmann/json
5458FetchContent_Declare (json URL https://github.com/nlohmann/json/archive/refs/heads/develop.zip)
5559FetchContent_MakeAvailable (json)
56-
57- if (MINJA_FUZZTEST_ENABLED)
58- # Fetch google/fuzztest (and indirectly, gtest)
59- FetchContent_Declare (fuzztest URL https://github.com/google/fuzztest/archive/refs/heads/main.zip)
60- FetchContent_MakeAvailable (fuzztest)
61- else ()
62- # Fetch gtest
63- FetchContent_Declare (googletest URL https://github.com/google/googletest/archive/refs/heads/main.zip)
64- FetchContent_MakeAvailable (googletest)
60+ target_link_libraries (minja INTERFACE nlohmann_json::nlohmann_json )
61+
62+ if (MINJA_TEST_ENABLED)
63+ if (MINJA_FUZZTEST_ENABLED)
64+ # Fetch google/fuzztest (and indirectly, gtest)
65+ FetchContent_Declare (fuzztest URL https://github.com/google/fuzztest/archive/refs/heads/main.zip)
66+ FetchContent_MakeAvailable (fuzztest)
67+ message (STATUS "${fuzztest_BINARY_DIR} : ${${fuzztest_BINARY_DIR} }" )
68+ else ()
69+ # Fetch gtest
70+ set (INSTALL_GTEST OFF )
71+ FetchContent_Declare (googletest URL https://github.com/google/googletest/archive/refs/heads/main.zip)
72+ FetchContent_MakeAvailable (googletest)
73+ endif ()
6574endif ()
6675
6776# Use ccache if installed
@@ -77,40 +86,57 @@ if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
7786 set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
7887endif ()
7988
80- set (Python_FIND_STRATEGY LOCATION CACHE STRING "Python find strategy" FORCE )
81- find_package (Python COMPONENTS Interpreter REQUIRED )
82- if (MINJA_USE_VENV)
83- # Create a python venv w/ the required dependencies
84- set (VENV_DIR "${CMAKE_BINARY_DIR} /venv" )
85- if (WIN32 )
86- set (VENV_PYTHON "${VENV_DIR} /Scripts/python.exe" )
87- else ()
88- set (VENV_PYTHON "${VENV_DIR} /bin/python" )
89+ if (MINJA_TEST_ENABLED)
90+ set (Python_FIND_STRATEGY LOCATION CACHE STRING "Python find strategy" FORCE )
91+ find_package (Python COMPONENTS Interpreter REQUIRED )
92+ if (MINJA_USE_VENV)
93+ # Create a python venv w/ the required dependencies
94+ set (VENV_DIR "${CMAKE_BINARY_DIR} /venv" )
95+ if (WIN32 )
96+ set (VENV_PYTHON "${VENV_DIR} /Scripts/python.exe" )
97+ else ()
98+ set (VENV_PYTHON "${VENV_DIR} /bin/python" )
99+ endif ()
100+ execute_process (
101+ COMMAND ${Python_EXECUTABLE} -m venv "${VENV_DIR} "
102+ COMMAND_ERROR_IS_FATAL ANY )
103+ execute_process (
104+ COMMAND ${VENV_PYTHON} -m pip install -r "${CMAKE_SOURCE_DIR} /requirements.txt"
105+ COMMAND_ERROR_IS_FATAL ANY )
106+ set (Python_EXECUTABLE "${VENV_PYTHON} " CACHE FILEPATH "Path to Python executable in venv" FORCE )
89107 endif ()
90- execute_process (
91- COMMAND ${Python_EXECUTABLE} -m venv "${VENV_DIR} "
92- COMMAND_ERROR_IS_FATAL ANY )
93- execute_process (
94- COMMAND ${VENV_PYTHON} -m pip install -r "${CMAKE_SOURCE_DIR} /requirements.txt"
95- COMMAND_ERROR_IS_FATAL ANY )
96- set (Python_EXECUTABLE "${VENV_PYTHON} " CACHE FILEPATH "Path to Python executable in venv" FORCE )
108+ message (STATUS "Python executable: ${Python_EXECUTABLE} " )
97109endif ()
98- message (STATUS "Python executable: ${Python_EXECUTABLE} " )
99110
100111find_program (CPPCHECK cppcheck )
101112if (CPPCHECK)
102113 set (CMAKE_CXX_CPPCHECK "${CPPCHECK} " -i ${json_SOURCE_DIR} /include/nlohmann/json.hpp)
103114 message (STATUS "cppcheck found: ${CPPCHECK} " )
104115endif ()
105116
106- message ( STATUS " ${fuzztest_BINARY_DIR} : ${ ${fuzztest_BINARY_DIR} }" )
107- include_directories (
108- include /minja
109- ${json_SOURCE_DIR} /include
117+ include ( GNUInstallDirs )
118+ target_include_directories ( minja INTERFACE
119+ $< BUILD_INTERFACE : ${CMAKE_CURRENT_SOURCE_DIR} / include >
120+ $< INSTALL_INTERFACE : ${CMAKE_INSTALL_INCLUDEDIR} >
110121)
111122
112- add_subdirectory (examples )
123+ install (FILES
124+ ${PROJECT_SOURCE_DIR} /include/minja/minja.hpp
125+ ${PROJECT_SOURCE_DIR} /include/minja/chat-template.hpp
126+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /minja
127+ )
128+ install (
129+ TARGETS minja
130+ EXPORT "${TARGETS_EXPORT_NAME} "
131+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /minja # for downstream projects
132+ )
113133
114- enable_testing ()
115- include (GoogleTest )
116- add_subdirectory (tests )
134+ if (MINJA_EXAMPLE_ENABLED)
135+ add_subdirectory (examples )
136+ endif ()
137+
138+ if (MINJA_TEST_ENABLED)
139+ enable_testing ()
140+ include (GoogleTest )
141+ add_subdirectory (tests )
142+ endif ()
0 commit comments