Update CMakeLists.txt

This commit is contained in:
antao 2018-09-14 23:54:06 +08:00
parent 4897c29a67
commit aaea4fb5ca
3 changed files with 67 additions and 56 deletions

View File

@ -7,23 +7,28 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
if(version LESS 4.9.0)
MESSAGE(STATUS "gcc is too old")
stop()
elseif (version LESS 6.1.0)
MESSAGE(STATUS "c++11")
set(CMAKE_CXX_STD_FLAGS c++11)
elseif(version LESS 7.1.0)
set(CMAKE_CXX_STD_FLAGS c++14)
MESSAGE(STATUS "c++14")
else()
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
message(STATUS "support c++17")
set(CMAKE_CXX_STD_FLAGS c++17)
#add_definitions(-DUSE_STD_ANY)
set(DR_DEFS "USE_STD_ANY")
MESSAGE(STATUS "c++17")
elseif(COMPILER_SUPPORTS_CXX14)
message(STATUS "support c++14")
set(CMAKE_CXX_STD_FLAGS c++14)
elseif(COMPILER_SUPPORTS_CXX11)
message(STATUS "support c++11")
set(CMAKE_CXX_STD_FLAGS c++11)
endif()
else()
set(CMAKE_CXX_STD_FLAGS c++11)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/)
#jsoncpp
find_package (Jsoncpp REQUIRED)

View File

@ -20,51 +20,57 @@ void create_project::handleCommand(std::vector<std::string> &parameters)
static void newCmakeFile(std::ofstream &cmakeFile,const std::string &projectName)
{
cmakeFile<< "cmake_minimum_required(VERSION 3.2)\n"
"Project("<<projectName<<")\n"
"link_libraries(drogon trantor uuid pthread jsoncpp ssl crypto dl z)\n"
"IF (CMAKE_SYSTEM_NAME MATCHES \"Linux\")\n"
" EXEC_PROGRAM (gcc ARGS \"--version | grep '^gcc'|awk '{print $3}' | sed s'/)//g' | sed s'/-.*//g'\" OUTPUT_VARIABLE version)\n"
" MESSAGE(STATUS \"This is gcc version:: \" ${version})\n"
" if(version LESS 4.9.0)\n"
" MESSAGE(STATUS \"gcc is too old\")\n"
" stop()\n"
" elseif (version LESS 6.1.0)\n"
" MESSAGE(STATUS \"c++11\")\n"
" set(CMAKE_CXX_STD_FLAGS c++11)\n"
" elseif(version LESS 7.1.0)\n"
" set(CMAKE_CXX_STD_FLAGS c++14)\n"
" MESSAGE(STATUS \"c++14\")\n"
" else()\n"
" set(CMAKE_CXX_STD_FLAGS c++17)\n"
" SET(DEFS \"USE_STD_ANY\")\n"
" MESSAGE(STATUS \"c++17\")\n"
"\n"
" endif()\n"
"else()\n"
" set(CMAKE_CXX_STD_FLAGS c++11)\n"
"endif()\n"
"if(CMAKE_BUILD_TYPE STREQUAL \"\")\n"
" set(CMAKE_BUILD_TYPE Release)\n"
"endif()\n"
"\n"
"set(CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS_DEBUG} -Wall -std=${CMAKE_CXX_STD_FLAGS}\")\n"
"set(CMAKE_CXX_FLAGS_RELEASE \"${CMAKE_CXX_FLAGS_RELEASE} -Wall -std=${CMAKE_CXX_STD_FLAGS}\")\n"
"aux_source_directory(./ SRC_DIR)\n"
"\n"
"FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp)\n"
"foreach(cspFile ${SCP_LIST})\n"
" message(STATUS \"cspFile:\" ${cspFile})\n"
" EXEC_PROGRAM(basename ARGS \"-s .csp ${cspFile}\" OUTPUT_VARIABLE classname)\n"
" message(STATUS \"view classname:\" ${classname})\n"
" add_custom_command(OUTPUT ${classname}.h ${classname}.cc\n"
" COMMAND drogon_ctl\n"
" ARGS create view ${cspFile}\n"
" DEPENDS ${cspFile}\n"
" VERBATIM )\n"
" set(VIEWSRC ${VIEWSRC} ${classname}.cc)\n"
"endforeach()\n"
"\n"
"add_executable("<<projectName<<" ${SRC_DIR} ${VIEWSRC})";
"Project("
<<projectName
<<")\n"
"link_libraries(drogon trantor uuid pthread jsoncpp ssl crypto dl z)\n"
"IF (CMAKE_SYSTEM_NAME MATCHES \"Linux\")\n"
" EXEC_PROGRAM (gcc ARGS \"--version | grep '^gcc'|awk '{print $3}' | sed s'/)//g' | sed s'/-.*//g'\" OUTPUT_VARIABLE version)\n"
" MESSAGE(STATUS \"This is gcc version:: \" ${version})\n"
" if(version LESS 4.9.0)\n"
" MESSAGE(STATUS \"gcc is too old\")\n"
" stop()\n"
" endif()\n"
" include(CheckCXXCompilerFlag)\n"
" CHECK_CXX_COMPILER_FLAG(\"-std=c++11\" COMPILER_SUPPORTS_CXX11)\n"
" CHECK_CXX_COMPILER_FLAG(\"-std=c++14\" COMPILER_SUPPORTS_CXX14)\n"
" CHECK_CXX_COMPILER_FLAG(\"-std=c++17\" COMPILER_SUPPORTS_CXX17)\n"
" if(COMPILER_SUPPORTS_CXX17)\n"
" message(STATUS \"support c++17\")\n"
" set(CMAKE_CXX_STD_FLAGS c++17)\n"
" set(DEFS \"USE_STD_ANY\")\n"
" elseif(COMPILER_SUPPORTS_CXX14)\n"
" message(STATUS \"support c++14\")\n"
" set(CMAKE_CXX_STD_FLAGS c++14)\n"
" elseif(COMPILER_SUPPORTS_CXX11)\n"
" message(STATUS \"support c++11\")\n"
" set(CMAKE_CXX_STD_FLAGS c++11)\n"
" endif()\n"
"else()\n"
" set(CMAKE_CXX_STD_FLAGS c++11)\n"
"endif()\n"
"if(CMAKE_BUILD_TYPE STREQUAL \"\")\n"
" set(CMAKE_BUILD_TYPE Release)\n"
"endif()\n"
"\n"
"set(CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS_DEBUG} -Wall -std=${CMAKE_CXX_STD_FLAGS}\")\n"
"set(CMAKE_CXX_FLAGS_RELEASE \"${CMAKE_CXX_FLAGS_RELEASE} -Wall -std=${CMAKE_CXX_STD_FLAGS}\")\n"
"aux_source_directory(./ SRC_DIR)\n"
"\n"
"FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp)\n"
"foreach(cspFile ${SCP_LIST})\n"
" message(STATUS \"cspFile:\" ${cspFile})\n"
" EXEC_PROGRAM(basename ARGS \"-s .csp ${cspFile}\" OUTPUT_VARIABLE classname)\n"
" message(STATUS \"view classname:\" ${classname})\n"
" add_custom_command(OUTPUT ${classname}.h ${classname}.cc\n"
" COMMAND drogon_ctl\n"
" ARGS create view ${cspFile}\n"
" DEPENDS ${cspFile}\n"
" VERBATIM )\n"
" set(VIEWSRC ${VIEWSRC} ${classname}.cc)\n"
"endforeach()\n"
"\n"
"add_executable("<<projectName<<" ${SRC_DIR} ${VIEWSRC})";
}
static void newMainFile(std::ofstream &mainFile)
{

@ -1 +1 @@
Subproject commit 29a0bf275c33e76fa8830166fceb9d045b65466b
Subproject commit 863a155f1725062a38b33a845e01be1e27c9286d