Skip to content

Commit

Permalink
The server created by wizard can be built by cmake.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengshuxin committed Nov 9, 2024
1 parent 015218b commit 12fad47
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/wizard/file_tmpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
95 changes: 95 additions & 0 deletions app/wizard/tmpl/http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 2.8)
project($<PROGRAM>)

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 $<PROGRAM> for release version")
elseif (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
message(STATUS "build $<PROGRAM> for debug version")
else()
message(STATUS "build $<PROGRAM> 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 "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
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($<PROGRAM> ${src_files})
target_link_libraries($<PROGRAM> ${lib_all})

###############################################################################
95 changes: 95 additions & 0 deletions app/wizard/tmpl/master/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 2.8)
project($<PROGRAM>)

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 $<PROGRAM> for release version")
elseif (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
message(STATUS "build $<PROGRAM> for debug version")
else()
message(STATUS "build $<PROGRAM> 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 "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
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($<PROGRAM> ${src_files})
target_link_libraries($<PROGRAM> ${lib_all})

###############################################################################

0 comments on commit 12fad47

Please sign in to comment.