1 cmake_minimum_required(VERSION 2.8)
3 if(NOT DEFINED CMAKE_BUILD_TYPE)
4 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
7 # This shows one way to build a standalone plugin
8 # outside of lws itself
10 project(lws-protocol-plugin-example C)
12 set(PACKAGE "lws-protocol-plugin-example")
13 set(CPACK_PACKAGE_NAME "${PACKAGE}")
14 set(CPACK_PACKAGE_VERSION "0.1")
15 set(CPACK_PACKAGE_VENDOR "andy@warmcat.com")
16 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}")
20 set(PLUGIN_NAME "protocol_example_standalone")
21 # space-separated list of sources
22 set(PLUGIN_SRCS protocol_example_standalone.c)
24 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
26 message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
28 # Try to find the current Git hash.
32 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
33 COMMAND "${GIT_EXECUTABLE}" describe
34 OUTPUT_VARIABLE GIT_HASH
35 OUTPUT_STRIP_TRAILING_WHITESPACE
38 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
40 OUTPUT_VARIABLE GIT_USER
41 OUTPUT_STRIP_TRAILING_WHITESPACE
44 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
46 OUTPUT_VARIABLE GIT_HOST
47 OUTPUT_STRIP_TRAILING_WHITESPACE
49 string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER})
50 set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH})
51 message("Git commit hash: ${LWS_BUILD_HASH}")
54 set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
56 source_group("Headers Private" FILES ${PLUGIN_HDR})
57 source_group("Sources" FILES ${PLUGIN_SRCS})
58 add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
60 target_link_libraries(${PLUGIN_NAME} -lwebsockets)
62 # Set test app specific defines.
63 set_property(TARGET ${PLUGIN_NAME}
64 PROPERTY COMPILE_DEFINITIONS
65 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
68 list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
70 install(TARGETS ${PLUGINS_LIST}
71 PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
72 DESTINATION share/libwebsockets-test-server/plugins