Skip to content

Commit

Permalink
* FIX [demo/cmake] Fix the cmake error when build independently.
Browse files Browse the repository at this point in the history
Signed-off-by: wanghaemq <[email protected]>
  • Loading branch information
wanghaEMQ committed Mar 27, 2024
1 parent df284a1 commit 6a417d9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 19 deletions.
10 changes: 7 additions & 3 deletions demo/async/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ project(nng-asyncdemo)

set(PARALLEL 128 CACHE STRING "Parallelism (min 4, max 1000)")

if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

find_package(Threads)

if (DEBUG)
Expand All @@ -28,9 +32,9 @@ if (DEBUG)
endif (DEBUG)

add_executable(server server.c)
target_link_libraries(server nng::nng)
target_link_libraries(server nng)
target_compile_definitions(server PRIVATE NNG_ELIDE_DEPRECATED PARALLEL=${PARALLEL})

add_executable(client client.c)
target_link_libraries(client nng::nng)
target_link_libraries(client nng)
target_compile_definitions(client PRIVATE NNG_ELIDE_DEPRECATED)
9 changes: 7 additions & 2 deletions demo/http_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ cmake_minimum_required(VERSION 3.13)
project(http_client)

# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)

if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

find_package(Threads)

Expand All @@ -27,5 +32,5 @@ if (DEBUG)
endif (DEBUG)

add_executable(http_client http_client.c)
target_link_libraries(http_client nng::nng)
target_link_libraries(http_client nng)
target_compile_definitions(http_client PRIVATE NNG_ELIDE_DEPRECATED)
8 changes: 6 additions & 2 deletions demo/mqtt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ cmake_minimum_required(VERSION 3.13)

project(mqtt_client)

find_package(nng CONFIG REQUIRED)
if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

find_package(Threads)

Expand All @@ -23,7 +27,7 @@ if (DEBUG)
endif (DEBUG)

add_executable(mqtt_client mqtt_client.c)
target_link_libraries(mqtt_client nng::nng)
target_link_libraries(mqtt_client nng)
target_link_libraries(mqtt_client ${CMAKE_THREAD_LIBS_INIT})

if(NNG_ENABLE_TLS)
Expand Down
9 changes: 7 additions & 2 deletions demo/mqtt_async/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ cmake_minimum_required(VERSION 3.13)

project(mqtt_async)

find_package(nng CONFIG REQUIRED)
if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

find_package(Threads)

if (DEBUG)
Expand All @@ -22,7 +27,7 @@ if (DEBUG)
endif (DEBUG)

add_executable(mqtt_async mqtt_async.c)
target_link_libraries(mqtt_async nng::nng)
target_link_libraries(mqtt_async nng)
target_link_libraries(mqtt_async ${CMAKE_THREAD_LIBS_INIT})

if(NNG_ENABLE_TLS)
Expand Down
8 changes: 6 additions & 2 deletions demo/mqttv5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ cmake_minimum_required(VERSION 3.13)

project(mqttv5_client)

find_package(nng CONFIG REQUIRED)
if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

find_package(Threads)

Expand All @@ -23,7 +27,7 @@ if (DEBUG)
endif (DEBUG)

add_executable(mqttv5_client mqttv5_client.c)
target_link_libraries(mqttv5_client nng::nng)
target_link_libraries(mqttv5_client nng)
target_link_libraries(mqttv5_client ${CMAKE_THREAD_LIBS_INIT})

if(NNG_ENABLE_TLS)
Expand Down
8 changes: 6 additions & 2 deletions demo/raw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ project(raw)

set(PARALLEL 128 CACHE STRING "Parallelism (min 4, max 1000)")

find_package(nng CONFIG REQUIRED)
if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

find_package(Threads)

Expand All @@ -28,5 +32,5 @@ if (DEBUG)
endif (DEBUG)

add_executable(raw raw.c)
target_link_libraries(raw nng::nng)
target_link_libraries(raw nng)
target_compile_definitions(raw PRIVATE NNG_ELIDE_DEPRECATED PARALLEL=${PARALLEL})
8 changes: 6 additions & 2 deletions demo/reqrep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ cmake_minimum_required(VERSION 3.13)

project(reqrep)

find_package(nng CONFIG REQUIRED)
if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

find_package(Threads)

Expand All @@ -29,5 +33,5 @@ endif (DEBUG)
# find_package(zerotiercore)

add_executable(reqrep reqrep.c)
target_link_libraries(reqrep nng::nng)
target_link_libraries(reqrep nng)
target_compile_definitions(reqrep PRIVATE NNG_ELIDE_DEPRECATED)
8 changes: 6 additions & 2 deletions demo/rest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ cmake_minimum_required(VERSION 3.13)

project(rest)

find_package(nng CONFIG REQUIRED)
if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

find_package(Threads)

Expand All @@ -26,5 +30,5 @@ if (DEBUG)
endif (DEBUG)

add_executable(rest-server server.c)
target_link_libraries(rest-server nng::nng)
target_link_libraries(rest-server nng)
target_compile_definitions(rest-server PRIVATE NNG_ELIDE_DEPRECATED)
8 changes: 6 additions & 2 deletions demo/stream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ cmake_minimum_required(VERSION 3.13)

project(stream)

find_package(nng CONFIG REQUIRED)
if (BUILD_DEMO)
else ()
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
endif (BUILD_DEMO)

if (DEBUG)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
Expand All @@ -34,4 +38,4 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/server.c)
endif()

target_link_libraries(stream nng::nng)
target_link_libraries(stream nng)

0 comments on commit 6a417d9

Please sign in to comment.