From 12fad473cf6df9645017c0ff741c44f225e39d18 Mon Sep 17 00:00:00 2001 From: zhengshuxin Date: Sat, 9 Nov 2024 16:46:16 +0800 Subject: [PATCH] The server created by wizard can be built by cmake. --- app/wizard/file_tmpl.cpp | 3 + app/wizard/tmpl/http/CMakeLists.txt | 95 +++++++++++++++++++++++++++ app/wizard/tmpl/master/CMakeLists.txt | 95 +++++++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 app/wizard/tmpl/http/CMakeLists.txt create mode 100644 app/wizard/tmpl/master/CMakeLists.txt diff --git a/app/wizard/file_tmpl.cpp b/app/wizard/file_tmpl.cpp index c9ad5e745..7d13f2ba1 100644 --- a/app/wizard/file_tmpl.cpp +++ b/app/wizard/file_tmpl.cpp @@ -76,6 +76,9 @@ bool file_tmpl::create_common() if (!copy_and_replace("Makefile", "Makefile")) { return false; } + if (!copy_and_replace("CMakeLists.txt", "CMakeLists.txt")) { + return false; + } if (!copy_and_replace("valgrind.sh", "valgrind.sh", true)) { return false; } diff --git a/app/wizard/tmpl/http/CMakeLists.txt b/app/wizard/tmpl/http/CMakeLists.txt new file mode 100644 index 000000000..0a75d91ae --- /dev/null +++ b/app/wizard/tmpl/http/CMakeLists.txt @@ -0,0 +1,95 @@ +cmake_minimum_required(VERSION 2.8) +project($) + +if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + message(FATAL_ERROR "Please into another dir to build!") +endif() + +if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + message(FATAL_ERROR "Please into another dir to build!") +endif() + +if (CMAKE_BUILD_TYPE STREQUAL "RELEASE") + message(STATUS "build $ for release version") +elseif (CMAKE_BUILD_TYPE STREQUAL "DEBUG") + message(STATUS "build $ for debug version") +else() + message(STATUS "build $ for default version") +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + add_definitions("-Wno-invalid-source-encoding") + include_directories("/usr/local/include") + SET(CMAKE_CXX_ARCHIVE_CREATE " Scr ") + SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") +elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") +else() + message(FATAL_ERROR "unknown CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}") +endif() + +############################################################################## + +set(home_path ${CMAKE_CURRENT_SOURCE_DIR}/../../..) +set(acl_inc ${home_path}/lib_acl/include) +set(acl_cpp_inc ${home_path}/lib_acl_cpp/include) +set(fiber_inc ${home_path}/lib_fiber/c/include) +set(fiber_cpp_inc ${home_path}/lib_fiber/cpp/include) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${acl_inc} + ${acl_cpp_inc} + ${fiber_inc} + ${fiber_cpp_inc} +) + +set(base_path ${CMAKE_CURRENT_SOURCE_DIR}) +set(src_paths ${base_path}) + +foreach(iter ${src_paths}) + aux_source_directory(${iter} src_files) +endforeach() + +############################################################################## + +#SET(CMAKE_VERBOSE_MAKEFILE on) + +add_definitions( + "-g" + "-W" + "-Wall" + "-Werror" + "-Wshadow" + "-Wformat" + "-Wpointer-arith" + "-D_REENTRANT" + "-Wno-long-long" + "-Wuninitialized" + "-D_POSIX_PTHREAD_SEMANTICS" + "-fexceptions" + "-Wno-unused-parameter" + "-Wno-error=deprecated-declarations" + "-Wno-deprecated-declarations" + "-fPIC" + "-O3" + "-std=c++11" +) + +set(libacl_all ${home_path}/libacl_all.a) +set(libfiber ${home_path}/lib_fiber/lib/libfiber.a) +set(libfiber_cpp ${home_path}/lib_fiber/lib/libfiber_cpp.a) + +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(lib_all ${libfiber_cpp} ${libacl_all} ${libfiber} -liconv -lz -lpthread -ldl) +elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") + set(lib_all ${libfiber_cpp} ${libacl_all} ${libfiber} -lz -lpthread -ldl) +endif() + +set(output_path ${CMAKE_CURRENT_SOURCE_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_path}) +link_directories(${output_path}) + +add_executable($ ${src_files}) +target_link_libraries($ ${lib_all}) + +############################################################################### diff --git a/app/wizard/tmpl/master/CMakeLists.txt b/app/wizard/tmpl/master/CMakeLists.txt new file mode 100644 index 000000000..0a75d91ae --- /dev/null +++ b/app/wizard/tmpl/master/CMakeLists.txt @@ -0,0 +1,95 @@ +cmake_minimum_required(VERSION 2.8) +project($) + +if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + message(FATAL_ERROR "Please into another dir to build!") +endif() + +if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + message(FATAL_ERROR "Please into another dir to build!") +endif() + +if (CMAKE_BUILD_TYPE STREQUAL "RELEASE") + message(STATUS "build $ for release version") +elseif (CMAKE_BUILD_TYPE STREQUAL "DEBUG") + message(STATUS "build $ for debug version") +else() + message(STATUS "build $ for default version") +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + add_definitions("-Wno-invalid-source-encoding") + include_directories("/usr/local/include") + SET(CMAKE_CXX_ARCHIVE_CREATE " Scr ") + SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") +elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") +else() + message(FATAL_ERROR "unknown CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}") +endif() + +############################################################################## + +set(home_path ${CMAKE_CURRENT_SOURCE_DIR}/../../..) +set(acl_inc ${home_path}/lib_acl/include) +set(acl_cpp_inc ${home_path}/lib_acl_cpp/include) +set(fiber_inc ${home_path}/lib_fiber/c/include) +set(fiber_cpp_inc ${home_path}/lib_fiber/cpp/include) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${acl_inc} + ${acl_cpp_inc} + ${fiber_inc} + ${fiber_cpp_inc} +) + +set(base_path ${CMAKE_CURRENT_SOURCE_DIR}) +set(src_paths ${base_path}) + +foreach(iter ${src_paths}) + aux_source_directory(${iter} src_files) +endforeach() + +############################################################################## + +#SET(CMAKE_VERBOSE_MAKEFILE on) + +add_definitions( + "-g" + "-W" + "-Wall" + "-Werror" + "-Wshadow" + "-Wformat" + "-Wpointer-arith" + "-D_REENTRANT" + "-Wno-long-long" + "-Wuninitialized" + "-D_POSIX_PTHREAD_SEMANTICS" + "-fexceptions" + "-Wno-unused-parameter" + "-Wno-error=deprecated-declarations" + "-Wno-deprecated-declarations" + "-fPIC" + "-O3" + "-std=c++11" +) + +set(libacl_all ${home_path}/libacl_all.a) +set(libfiber ${home_path}/lib_fiber/lib/libfiber.a) +set(libfiber_cpp ${home_path}/lib_fiber/lib/libfiber_cpp.a) + +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(lib_all ${libfiber_cpp} ${libacl_all} ${libfiber} -liconv -lz -lpthread -ldl) +elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") + set(lib_all ${libfiber_cpp} ${libacl_all} ${libfiber} -lz -lpthread -ldl) +endif() + +set(output_path ${CMAKE_CURRENT_SOURCE_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_path}) +link_directories(${output_path}) + +add_executable($ ${src_files}) +target_link_libraries($ ${lib_all}) + +###############################################################################