diff --git a/CMakeLists.txt b/CMakeLists.txt index 1852058..16dd390 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,74 +1,61 @@ cmake_minimum_required (VERSION 3.2) -Project(core) +project(core) -link_directories(/usr/local/lib) -link_libraries(drogon trantor pthread dl) +include(CheckIncludeFileCXX) -IF (CMAKE_SYSTEM_NAME MATCHES "Linux") - EXEC_PROGRAM (gcc ARGS "--version | grep '^gcc'|awk '{print $3}' | sed s'/)//g' | sed s'/-.*//g'" OUTPUT_VARIABLE version) - MESSAGE(STATUS "This is gcc version:: " ${version}) - if(version LESS 5.4.0) - MESSAGE(STATUS "gcc is too old") - stop() - elseif(version LESS 7.1.0) - set(CMAKE_CXX_STD_FLAGS c++14) - MESSAGE(STATUS "c++14") - else() - set(CMAKE_CXX_STD_FLAGS c++17) - MESSAGE(STATUS "c++17") - endif() +check_include_file_cxx(any HAS_ANY) +check_include_file_cxx(string_view HAS_STRING_VIEW) +if(HAS_ANY AND HAS_STRING_VIEW) + set(CMAKE_CXX_STANDARD 17) else() - set(CMAKE_CXX_STD_FLAGS c++17) + set(CMAKE_CXX_STANDARD 14) endif() -if(CMAKE_BUILD_TYPE STREQUAL "") - set(CMAKE_BUILD_TYPE Release) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +########## +# If you include the drogon source code locally in your project, use this method to add drogon +# add_subdirectory(drogon) +# set(Drogon_DIR ${PROJECT_BINARY_DIR}/drogon) +# find_package(Drogon CONFIG REQUIRED NO_DEFAULT_PATH) +# include_directories(${DROGON_INCLUDE_DIRS}) +# link_libraries(${DROGON_LIBRARIES}) +########## + +find_package(Drogon CONFIG REQUIRED) +include_directories(${DROGON_INCLUDE_DIRS}) +link_libraries(${DROGON_LIBRARIES}) + +if(CMAKE_CXX_STANDARD LESS 17) + #With C++14, use boost to support any and string_view + message(STATUS "use c++14") + find_package(Boost 1.61.0 REQUIRED) + include_directories(${Boost_INCLUDE_DIRS}) +else() + message(STATUS "use c++17") endif() -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -std=${CMAKE_CXX_STD_FLAGS}") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -std=${CMAKE_CXX_STD_FLAGS}") +aux_source_directory(./ SRC_DIR) +aux_source_directory(controllers CTL_SRC) +aux_source_directory(filters FILTER_SRC) +aux_source_directory(plugins PLUGIN_SRC) +aux_source_directory(models MODEL_SRC) +aux_source_directory(helpers HELPER_SRC) -set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/) - -#jsoncpp -find_package (Jsoncpp REQUIRED) -include_directories(${JSONCPP_INCLUDE_DIRS}) -link_libraries(${JSONCPP_LIBRARIES}) - -#uuid -find_package (UUID REQUIRED) -include_directories(${UUID_INCLUDE_DIR}) -link_libraries(${UUID_LIBRARIES}) - -#OpenSSL -find_package (OpenSSL) -if(OpenSSL_FOUND) - include_directories(${OPENSSL_INCLUDE_DIR}) - link_libraries(${OPENSSL_LIBRARIES}) -endif() - -#zlib -find_package(ZLIB REQUIRED) -include_directories(${ZLIB_INCLUDE_DIR}) -link_libraries(${ZLIB_LIBRARIES}) - -#Find sqlite3. -find_package (SQLite3) -if (SQLITE3_FOUND) - include_directories(${SQLITE3_INCLUDE_DIRS}) - link_libraries(${SQLITE3_LIBRARIES}) -endif() - -AUX_SOURCE_DIRECTORY(./ SRC_DIR) -AUX_SOURCE_DIRECTORY(controllers CTL_SRC) -AUX_SOURCE_DIRECTORY(filters FILTER_SRC) -AUX_SOURCE_DIRECTORY(plugins PLUGIN_SRC) -AUX_SOURCE_DIRECTORY(models MODEL_SRC) -AUX_SOURCE_DIRECTORY(helpers HELPER_SRC) - -include_directories(/usr/local/include) +file(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp) +foreach(cspFile ${SCP_LIST}) + message(STATUS "cspFile:" ${cspFile}) + EXEC_PROGRAM(basename ARGS "${cspFile} .csp" OUTPUT_VARIABLE classname) + message(STATUS "view classname:" ${classname}) + ADD_CUSTOM_COMMAND(OUTPUT ${classname}.h ${classname}.cc + COMMAND drogon_ctl + ARGS create view ${cspFile} + DEPENDS ${cspFile} + VERBATIM ) + set(VIEWSRC ${VIEWSRC} ${classname}.cc) +endforeach() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +add_executable(core ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC} ${PLUGIN_SRC} ${MODEL_SRC} ${HELPER_SRC}) -configure_file("config.json" "config.json" COPYONLY) -add_executable(core ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${PLUGIN_SRC} ${MODEL_SRC} ${HELPER_SRC})