1cmake_minimum_required(VERSION 2.8.12) 2find_package(libwebsockets CONFIG REQUIRED) 3 4if(NOT DEFINED CMAKE_BUILD_TYPE) 5 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") 6endif() 7 8# This shows one way to build a standalone plugin 9# outside of lws itself 10 11project(lws-protocol-plugin-example C) 12 13set(PACKAGE "lws-protocol-plugin-example") 14set(CPACK_PACKAGE_NAME "${PACKAGE}") 15set(CPACK_PACKAGE_VERSION "0.1") 16set(CPACK_PACKAGE_VENDOR "andy@warmcat.com") 17set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}") 18set(SOVERSION "1") 19set(VERSION "0.1") 20 21set(PLUGIN_NAME "protocol_example_standalone") 22# space-separated list of sources 23set(PLUGIN_SRCS protocol_example_standalone.c) 24 25set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") 26 27message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'") 28 29# Try to find the current Git hash. 30find_package(Git) 31if(GIT_EXECUTABLE) 32 execute_process( 33 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 34 COMMAND "${GIT_EXECUTABLE}" describe 35 OUTPUT_VARIABLE GIT_HASH 36 OUTPUT_STRIP_TRAILING_WHITESPACE 37 ) 38 execute_process( 39 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 40 COMMAND "whoami" 41 OUTPUT_VARIABLE GIT_USER 42 OUTPUT_STRIP_TRAILING_WHITESPACE 43 ) 44 execute_process( 45 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 46 COMMAND "hostname" 47 OUTPUT_VARIABLE GIT_HOST 48 OUTPUT_STRIP_TRAILING_WHITESPACE 49 ) 50 string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER}) 51 set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH}) 52 message("Git commit hash: ${LWS_BUILD_HASH}") 53endif() 54 55set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") 56 57source_group("Headers Private" FILES ${PLUGIN_HDR}) 58source_group("Sources" FILES ${PLUGIN_SRCS}) 59add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR}) 60target_compile_definitions(${PLUGIN_NAME} PRIVATE LWS_BUILDING_SHARED) 61 62target_link_libraries(${PLUGIN_NAME} -lwebsockets ${LIBWEBSOCKETS_DEP_LIBS}) 63 64# Set test app specific defines. 65set_property(TARGET ${PLUGIN_NAME} 66 PROPERTY COMPILE_DEFINITIONS 67 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins" 68) 69 70list(APPEND PLUGINS_LIST ${PLUGIN_NAME}) 71 72install(TARGETS ${PLUGINS_LIST} 73 PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ 74 DESTINATION share/libwebsockets-test-server/plugins 75 COMPONENT plugins) 76