function(QUICKJS_PIC) string(RANDOM RANDOM) set(CMAKETMP ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${RANDOM}) file(WRITE ${CMAKETMP}/${RANDOM}.c "#include \"quickjs.h\" JSModuleDef *js_init_module(JSContext *ctx, char const *module_name) {\n\treturn JS_NewCModule(ctx, module_name, 0);\n} ") file(WRITE ${CMAKETMP}/CMakeLists.txt "cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(CMAKE_TRY_COMPILE C)\nadd_library(${RANDOM} MODULE ${RANDOM}.c) target_include_directories(${RANDOM} PRIVATE ${QUICKJS_INCLUDE_DIR}) target_link_libraries(${RANDOM} PRIVATE ${QUICKJS_LIBRARY}) ") try_compile(QUICKJS_PIC ${CMAKETMP} ${CMAKETMP} CMAKE_TRY_COMPILE) if(QUICKJS_PIC) set(QUICKJS_PIC 1 CACHE INTERNAL "QuickJS complied with PIC") else() set(QUICKJS_PIC 0 CACHE INTERNAL "QuickJS complied with PIC") endif() file(REMOVE_RECURSE ${CMAKETMP}) endfunction() if(NOT DEFINED QUICKJS_PIC) QUICKJS_PIC() endif()