|
1 | 1 | cmake_minimum_required(VERSION 3.15)
|
2 | 2 | project (crow_examples)
|
3 | 3 |
|
4 |
| -# Define Required libraries |
5 |
| -list(APPEND REQUIRED_LIBRARIES |
6 |
| - ${Boost_LIBRARIES} |
7 |
| - ${CMAKE_THREAD_LIBS_INIT} |
8 |
| - z |
9 |
| -) |
| 4 | +include(${CMAKE_SOURCE_DIR}/cmake/compiler_options.cmake) |
10 | 5 |
|
11 |
| -if (MSVC) |
12 |
| - add_executable(example_vs example_vs.cpp) |
13 |
| - target_compile_options(example_vs PRIVATE "${compiler_options}") |
14 |
| - target_link_libraries(example_vs ) |
15 |
| -else () |
16 |
| - add_executable(helloworld helloworld.cpp) |
17 |
| - target_compile_options(helloworld PRIVATE "${compiler_options}") |
18 |
| - target_link_libraries(helloworld PUBLIC ${REQUIRED_LIBRARIES}) |
| 6 | +add_executable(helloworld helloworld.cpp) |
| 7 | +target_compile_options(helloworld PRIVATE "${compiler_options}") |
| 8 | +target_link_libraries(helloworld PUBLIC crow) |
19 | 9 |
|
| 10 | +if(ZLIB_FOUND) |
20 | 11 | add_executable(example_compression example_compression.cpp)
|
21 | 12 | target_compile_options(example_compression PRIVATE "${compiler_options}")
|
22 |
| - target_link_libraries(example_compression ${REQUIRED_LIBRARIES}) |
23 |
| - |
24 |
| - # If OpenSSL is not found, the example won't be built |
25 |
| - if (OPENSSL_FOUND) |
26 |
| - add_executable(example_ssl ssl/example_ssl.cpp) |
27 |
| - target_compile_options(example_ssl PRIVATE "${compiler_options}") |
28 |
| - target_link_libraries(example_ssl PUBLIC ${REQUIRED_LIBRARIES} ${OPENSSL_LIBRARIES}) |
29 |
| - else() |
30 |
| - message(STATUS "example_ssl Example deactivated - OpenSSL was not found") |
31 |
| - endif() |
| 13 | + target_link_libraries(example_compression crow) |
| 14 | +else() |
| 15 | + message(STATUS "example_compression Example deactivated - ZLIB was not found") |
| 16 | +endif() |
32 | 17 |
|
33 |
| - add_executable(example_websocket websocket/example_ws.cpp) |
34 |
| - target_compile_options(example_websocket PRIVATE "${compiler_options}") |
35 |
| - target_link_libraries(example_websocket ) |
36 |
| - target_link_libraries(example_websocket PUBLIC ${REQUIRED_LIBRARIES}) |
37 |
| - add_custom_command(OUTPUT ws.html |
38 |
| - COMMAND ${CMAKE_COMMAND} -E |
39 |
| - copy ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html ${CMAKE_CURRENT_BINARY_DIR}/templates/ws.html |
40 |
| - DEPENDS ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html |
41 |
| - ) |
42 |
| - add_custom_target(example_ws_copy ALL DEPENDS ws.html) |
| 18 | +# If OpenSSL is not found, the example won't be built |
| 19 | +if (OPENSSL_FOUND) |
| 20 | + add_executable(example_ssl ssl/example_ssl.cpp) |
| 21 | + target_compile_options(example_ssl PRIVATE "${compiler_options}") |
| 22 | + target_link_libraries(example_ssl PUBLIC crow) |
| 23 | +else() |
| 24 | + message(STATUS "example_ssl Example deactivated - OpenSSL was not found") |
| 25 | +endif() |
43 | 26 |
|
44 |
| - add_executable(basic_example example.cpp) |
45 |
| - target_compile_options(basic_example PRIVATE "${compiler_options}") |
46 |
| - target_link_libraries(basic_example PUBLIC ${REQUIRED_LIBRARIES}) |
| 27 | +add_executable(example_websocket websocket/example_ws.cpp) |
| 28 | +target_compile_options(example_websocket PRIVATE "${compiler_options}") |
| 29 | +target_link_libraries(example_websocket PUBLIC crow) |
| 30 | +add_custom_command(OUTPUT ws.html |
| 31 | + COMMAND ${CMAKE_COMMAND} -E |
| 32 | + copy ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html ${CMAKE_CURRENT_BINARY_DIR}/templates/ws.html |
| 33 | + DEPENDS ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html |
| 34 | +) |
| 35 | +add_custom_target(example_ws_copy ALL DEPENDS ws.html) |
47 | 36 |
|
48 |
| - if (Tcmalloc_FOUND) |
49 |
| - target_link_libraries(basic_example PRIVATE ${Tcmalloc_LIBRARIES}) |
50 |
| - endif(Tcmalloc_FOUND) |
| 37 | +add_executable(basic_example example.cpp) |
| 38 | +target_compile_options(basic_example PRIVATE "${compiler_options}") |
| 39 | +target_link_libraries(basic_example PUBLIC crow) |
51 | 40 |
|
| 41 | +if(CROW_AMALGAMATE) |
52 | 42 | add_executable(example_with_all example_with_all.cpp)
|
53 |
| - add_dependencies(example_with_all amalgamation) |
| 43 | + add_dependencies(example_with_all crow_amalgamated) |
54 | 44 | target_compile_options(example_with_all PRIVATE "${compiler_options}")
|
55 |
| - target_link_libraries(example_with_all PUBLIC ${REQUIRED_LIBRARIES}) |
| 45 | + target_link_libraries(example_with_all PUBLIC crow) |
| 46 | +endif() |
56 | 47 |
|
57 |
| - add_custom_command(OUTPUT example_test.py |
58 |
| - COMMAND ${CMAKE_COMMAND} -E |
59 |
| - copy ${PROJECT_SOURCE_DIR}/example_test.py ${CMAKE_CURRENT_BINARY_DIR}/example_test.py |
60 |
| - DEPENDS ${PROJECT_SOURCE_DIR}/example_test.py |
61 |
| - ) |
62 |
| - add_custom_target(example_copy ALL DEPENDS example_test.py) |
| 48 | +add_executable(example_chat example_chat.cpp) |
| 49 | +target_compile_options(example_chat PRIVATE "${compiler_options}") |
| 50 | +target_link_libraries(example_chat PUBLIC crow) |
63 | 51 |
|
64 |
| - add_executable(example_chat example_chat.cpp) |
65 |
| - target_compile_options(example_chat PRIVATE "${compiler_options}") |
66 |
| - target_link_libraries(example_chat PUBLIC ${REQUIRED_LIBRARIES}) |
| 52 | +add_executable(example_static_file example_static_file.cpp) |
| 53 | +target_compile_options(example_static_file PRIVATE "${compiler_options}") |
| 54 | +target_link_libraries(example_static_file PUBLIC crow) |
67 | 55 |
|
68 |
| - add_executable(example_static_file example_static_file.cpp) |
69 |
| - target_compile_options(example_static_file PRIVATE "${compiler_options}") |
70 |
| - target_link_libraries(example_static_file PUBLIC ${REQUIRED_LIBRARIES}) |
| 56 | +add_executable(example_catchall example_catchall.cpp) |
| 57 | +target_compile_options(example_catchall PRIVATE "${compiler_options}") |
| 58 | +target_link_libraries(example_catchall PUBLIC crow) |
71 | 59 |
|
72 |
| - add_executable(example_catchall example_catchall.cpp) |
73 |
| - target_compile_options(example_catchall PRIVATE "${compiler_options}") |
74 |
| - target_link_libraries(example_catchall PUBLIC ${REQUIRED_LIBRARIES}) |
75 |
| - |
76 |
| - add_executable(example_json_map example_json_map.cpp) |
77 |
| - target_compile_options(example_json_map PRIVATE "${compiler_options}") |
78 |
| - target_link_libraries(example_json_map PUBLIC ${REQUIRED_LIBRARIES}) |
| 60 | +add_executable(example_json_map example_json_map.cpp) |
| 61 | +target_compile_options(example_json_map PRIVATE "${compiler_options}") |
| 62 | +target_link_libraries(example_json_map PUBLIC crow) |
79 | 63 |
|
80 |
| - add_executable(example_blueprint example_blueprint.cpp) |
81 |
| - target_compile_options(example_blueprint PRIVATE "${compiler_options}") |
82 |
| - target_link_libraries(example_blueprint PUBLIC ${REQUIRED_LIBRARIES}) |
| 64 | +add_executable(example_blueprint example_blueprint.cpp) |
| 65 | +target_compile_options(example_blueprint PRIVATE "${compiler_options}") |
| 66 | +target_link_libraries(example_blueprint PUBLIC crow) |
83 | 67 |
|
84 |
| - add_custom_command(OUTPUT example_chat.html |
| 68 | +add_custom_command(OUTPUT example_chat.html |
| 69 | + COMMAND ${CMAKE_COMMAND} -E |
| 70 | + copy ${PROJECT_SOURCE_DIR}/example_chat.html ${CMAKE_CURRENT_BINARY_DIR}/example_chat.html |
| 71 | + DEPENDS ${PROJECT_SOURCE_DIR}/example_chat.html |
| 72 | +) |
| 73 | +add_custom_target(example_chat_copy ALL DEPENDS example_chat.html) |
| 74 | + |
| 75 | +if (MSVC) |
| 76 | + add_executable(example_vs example_vs.cpp) |
| 77 | + target_compile_options(example_vs PRIVATE "${compiler_options}") |
| 78 | + target_link_libraries(example_vs crow) |
| 79 | +else () |
| 80 | + add_custom_command(OUTPUT example_test.py |
85 | 81 | COMMAND ${CMAKE_COMMAND} -E
|
86 |
| - copy ${PROJECT_SOURCE_DIR}/example_chat.html ${CMAKE_CURRENT_BINARY_DIR}/example_chat.html |
87 |
| - DEPENDS ${PROJECT_SOURCE_DIR}/example_chat.html |
| 82 | + copy ${PROJECT_SOURCE_DIR}/example_test.py ${CMAKE_CURRENT_BINARY_DIR}/example_test.py |
| 83 | + DEPENDS ${PROJECT_SOURCE_DIR}/example_test.py |
88 | 84 | )
|
89 |
| - add_custom_target(example_chat_copy ALL DEPENDS example_chat.html) |
90 |
| - |
| 85 | + add_custom_target(example_copy ALL DEPENDS example_test.py) |
91 | 86 | endif()
|
0 commit comments