 +#export(PACKAGE libwebsockets)
  
  # Generate the config file for the build-tree.
- set(LWS__INCLUDE_DIRS 
+-set(LWS__INCLUDE_DIRS 
++set(LWS__INCLUDE_DIRS
+     "${PROJECT_SOURCE_DIR}/lib"
+     "${PROJECT_BINARY_DIR}")
+ set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories")
+ configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
+-                ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake 
++                ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake
+                 @ONLY)
+ 
+ # Generate the config file for the installation tree.
+ get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE)
+ get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE)
+-file(RELATIVE_PATH 
+-    REL_INCLUDE_DIR 
++file(RELATIVE_PATH
++    REL_INCLUDE_DIR
+     "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}"
+     "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir.
+ 
+-# Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in, 
++# Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in,
+ # we escape it here so it's evaluated when it is included instead
+-# so that the include dirs are given relative to where the 
++# so that the include dirs are given relative to where the
+ # config file is located.
+-set(LWS__INCLUDE_DIRS 
+-    "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}") 
++set(LWS__INCLUDE_DIRS
++    "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}")
+ configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
+-                ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake 
++                ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake
+                 @ONLY)
+ 
+ # Generate version info for both build-tree and install-tree.
+ configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in
+-                ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake 
++                ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake
+                 @ONLY)
+ 
+ 			set_target_properties(${LWS_LIBRARIES}
+@@ -2086,7 +2095,7 @@
+ 		      plugins/generic-sessions/assets/index.html
+ 		DESTINATION share/libwebsockets-test-server/generic-sessions
+ 			COMPONENT examples)
+-	install(FILES plugins/generic-sessions/assets/successful-login.html 
++	install(FILES plugins/generic-sessions/assets/successful-login.html
+ 		DESTINATION share/libwebsockets-test-server/generic-sessions/needauth
+ 			COMPONENT examples)
+ 	install(FILES plugins/generic-sessions/assets/admin-login.html

--- CMakeLists.txt.orig	2019-02-15 22:43:24.189777825 +0100
+++ CMakeLists.txt	2019-02-15 22:49:23.543102100 +0100
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.9)
+cmake_minimum_required(VERSION 2.6.4)
 
 # General Advice
 #
@@ -1055,9 +1055,9 @@
     endif()
 
     if (UNIX AND NOT LWS_WITH_ESP32)

     endif()
 endif ()
 
-if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS)
-	if (UNIX AND LWS_HAVE_PTHREAD_H)
-	# jeez clang understands -pthread but dies if he sees it at link time!
-	# http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
-	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
+if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+  if (NOT LWS_WITHOUT_TESTAPPS)
+	  if (UNIX AND LWS_HAVE_PTHREAD_H)
+	    # jeez clang understands -pthread but dies if he sees it at link time!
+	    # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
+	    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
     endif()
+  endif()
 endif()
 
-if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
+if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
 	# otherwise osx blows a bunch of openssl deprecated api errors
 	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" )
 endif()
@@ -1157,7 +1163,7 @@
 
 # Set the so version of the lib.
 # Equivalent to LDFLAGS=-version-info x:x:x
-if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
+if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
 	foreach(lib ${LWS_LIBRARIES})
 		set_target_properties(${lib}
 			PROPERTIES
@@ -1520,7 +1526,7 @@
 		endif()
 	endif()
 
-	list(APPEND TEST_SERVER_DATA 
+	list(APPEND TEST_SERVER_DATA
 		"${TEST_SERVER_SSL_KEY}"
 		"${TEST_SERVER_SSL_CERT}")
 endif()
@@ -1532,7 +1538,8 @@
 # Test applications
 #
 set(TEST_APP_LIST)
-if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS)
+if (LWS_ROLE_H1 OR LWS_ROLE_H2)
+if (NOT LWS_WITHOUT_TESTAPPS)
 	#
 	# Helper function for adding a test app.
 	#
@@ -1608,7 +1615,7 @@
 
 	if (UNIX AND LWS_WITH_PLUGINS)
 		set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
-		if(NOT((${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") OR (${CMAKE_SYSTEM_NAME} MATCHES "QNX")))
+		if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "QNX")
 			target_link_libraries(websockets dl)
 		endif()
 	endif()
@@ -1666,8 +1673,8 @@
 			# Set defines for this executable only.
 			set_property(
 				TARGET test-server-extpoll
-				PROPERTY COMPILE_DEFINITIONS 
-					EXTERNAL_POLL 
+				PROPERTY COMPILE_DEFINITIONS
+					EXTERNAL_POLL
 					INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
 				)
 
@@ -1700,7 +1707,7 @@
 			"${PROJECT_SOURCE_DIR}/test-apps/test.html")
 
 		add_custom_command(TARGET test-server
-						POST_BUILD 
+						POST_BUILD
 						COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server")
 
 		# Copy the file needed to run the server so that the test apps can
@@ -1708,7 +1715,7 @@
 		foreach (TEST_FILE ${TEST_SERVER_DATA})
 			if (EXISTS ${TEST_FILE})
 				add_custom_command(TARGET test-server
-							POST_BUILD 
+							POST_BUILD
 							COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
 			endif()
 		endforeach()
@@ -1723,8 +1730,8 @@
 		endif()
 
 	endif(NOT LWS_WITHOUT_CLIENT)
-	
-	
+
+
 	if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
 		macro(create_plugin PLUGIN_NAME PLUGIN_INCLUDE MAIN_SRC S2 S3)
 
@@ -1755,7 +1762,7 @@
 		source_group("Headers Private"   FILES ${PLUGIN_HDR})
 		source_group("Sources"   FILES ${PLUGIN_SRCS})
 		add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
-		
+
 		target_link_libraries(${PLUGIN_NAME} websockets_shared)
 		add_dependencies(${PLUGIN_NAME} websockets_shared)
 		include_directories(${PLUGIN_INCLUDE})
@@ -1773,7 +1780,7 @@
 		list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
 
 		endmacro()
-		
+
 if (LWS_ROLE_WS)
 		create_plugin(protocol_dumb_increment ""
 			      "plugins/protocol_dumb_increment.c" "" "")
@@ -1873,7 +1880,8 @@
 			endforeach()
 		endif()
 	endif()
-endif((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS)
+endif(NOT LWS_WITHOUT_TESTAPPS)
+endif(LWS_ROLE_H1 OR LWS_ROLE_H2)
 
 if (LWS_WITH_LWSWS)
 		list(APPEND LWSWS_SRCS
@@ -1967,38 +1975,39 @@
             FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
 endif()
 
