5 # Find quickjs include dirs and libraries.
10 # This module defines the following :ref:`Imported Targets <Imported Targets>`:
17 # This module defines the following variables:
21 # ``QUICKJS_INCLUDE_DIR``
23 # ``QUICKJS_LIBRARIES``
34 # Search results are saved persistently in CMake cache entries:
36 # ``QUICKJS_INCLUDE_DIR``
38 # ``QUICKJS_LIBRARY_IPO``
46 include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
47 find_path(QUICKJS_INCLUDE_DIR NAMES quickjs.h PATH_SUFFIXES quickjs)
48 mark_as_advanced(QUICKJS_INCLUDE_DIR)
50 find_program(QJSC_EXECUTABLE NAMES qjsc)
51 mark_as_advanced(QJSC_EXECUTABLE)
53 find_program(QJS_EXECUTABLE NAMES qjs)
54 mark_as_advanced(QJS_EXECUTABLE)
56 if(EXISTS "${QJS_EXECUTABLE}")
57 execute_process(COMMAND ${QJS_EXECUTABLE} -h OUTPUT_VARIABLE QUICKJS_VERSION)
58 elseif(EXISTS "${QJSC_EXECUTABLE}")
59 execute_process(COMMAND ${QJSC_EXECUTABLE} -h OUTPUT_VARIABLE QUICKJS_VERSION)
62 string(REGEX REPLACE ".*version[ ]+([^\n ]+).*" "\\1" QUICKJS_VERSION "${QUICKJS_VERSION}")
65 find_library(QUICKJS_LIBRARY_IPO NAMES quickjs.lto PATH_SUFFIXES quickjs)
66 find_library(QUICKJS_LIBRARY NAMES quickjs PATH_SUFFIXES quickjs)
67 mark_as_advanced(QUICKJS_LIBRARY_IPO QUICKJS_LIBRARY)
68 if(EXISTS "${QUICKJS_LIBRARY}" OR EXISTS "${QUICKJS_LIBRARY_IPO}")
69 if(EXISTS "${QUICKJS_LIBRARY_IPO}")
70 list(APPEND QUICKJS_LIBRARIES ${QUICKJS_LIBRARY_IPO})
71 elseif(EXISTS "${QUICKJS_LIBRARY}")
72 list(APPEND QUICKJS_LIBRARIES ${QUICKJS_LIBRARY})
75 list(APPEND QUICKJS_LIBRARIES m ${CMAKE_DL_LIBS})
77 find_library(QUICKJS_PTHREAD_LIBRARY pthread)
78 mark_as_advanced(QUICKJS_PTHREAD_LIBRARY)
79 if(QUICKJS_PTHREAD_LIBRARY)
80 list(APPEND QUICKJS_LIBRARIES pthread)
84 find_package_handle_standard_args(QuickJS
96 if(NOT TARGET quickjs AND QUICKJS_FOUND)
97 set(libraries ${QUICKJS_LIBRARIES})
98 if(EXISTS "${QUICKJS_LIBRARY_IPO}" OR EXISTS "${QUICKJS_LIBRARY}")
99 add_library(quickjs UNKNOWN IMPORTED)
100 set_target_properties(quickjs PROPERTIES
101 INTERFACE_INCLUDE_DIRECTORIES "${QUICKJS_INCLUDE_DIR}"
102 IMPORTED_LINK_INTERFACE_LANGUAGES C
104 if(EXISTS "${QUICKJS_LIBRARY_IPO}")
105 list(REMOVE_ITEM libraries ${QUICKJS_LIBRARY_IPO})
106 set_property(TARGET quickjs PROPERTY
107 IMPORTED_LOCATION "${QUICKJS_LIBRARY_IPO}"
109 elseif(EXISTS "${QUICKJS_LIBRARY}")
110 list(REMOVE_ITEM libraries ${QUICKJS_LIBRARY})
111 set_property(TARGET quickjs PROPERTY
112 IMPORTED_LOCATION "${QUICKJS_LIBRARY}"
115 set_property(TARGET quickjs APPEND PROPERTY
116 INTERFACE_LINK_LIBRARIES ${libraries}