drogon icon indicating copy to clipboard operation
drogon copied to clipboard

Linux and windows Problem to build Simple project using "./drogon_ctl create project" getting : Unknown CMake command "drogon_create_views".

Open meiry opened this issue 2 years ago • 9 comments

in linux using :

vagrant@vagrant:~/cpp/test_web/build$ g++ --version
g++ (Ubuntu 10.3.0-1ubuntu1~18.04~1) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.

OS : 
vagrant@vagrant:~/cpp/test_web/build$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu


this is looks like broken both in windows and linux after compiling the framework in linux ( easy ) and windows VSC++ ( not strath forward alot of manual work )

im come to the point of creating the project and compile but in both windows and linux im getting problems . i added the drogon dir inside the third_party vased on this issue : https://github.com/drogonframework/drogon/issues/627 also removed from the CMakeLists.txt the 2 linles

But i like first to fix it in linux but notice that i verified it and in windows its the same prblem with the same error

See content :

cmake_minimum_required(VERSION 3.5)
project(/home/vagrant/cpp/drogon/test_web CXX)

include(CheckIncludeFileCXX)

check_include_file_cxx(any HAS_ANY)
check_include_file_cxx(string_view HAS_STRING_VIEW)
check_include_file_cxx(coroutine HAS_COROUTINE)
if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
    # Do nothing
elseif (HAS_ANY AND HAS_STRING_VIEW AND HAS_COROUTINE)
    set(CMAKE_CXX_STANDARD 20)
elseif (HAS_ANY AND HAS_STRING_VIEW)
    set(CMAKE_CXX_STANDARD 17)
else ()
    set(CMAKE_CXX_STANDARD 14)
endif ()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(${PROJECT_NAME} main.cc)

# ##############################################################################
# If you include the drogon source code locally in your project, use this method
# to add drogon
# add_subdirectory(drogon)
# target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
#
# and comment out the following lines
#find_package(Drogon CONFIG REQUIRED)
#target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)

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

if (CMAKE_CXX_STANDARD LESS 17)
    # With C++14, use boost to support any, string_view and filesystem
    message(STATUS "use c++14")
    find_package(Boost 1.61.0 REQUIRED)
    target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost)
elseif (CMAKE_CXX_STANDARD LESS 20)
    message(STATUS "use c++17")
else ()
    message(STATUS "use c++20")
endif ()

aux_source_directory(controllers CTL_SRC)
aux_source_directory(filters FILTER_SRC)
aux_source_directory(plugins PLUGIN_SRC)
aux_source_directory(models MODEL_SRC)

drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
                    ${CMAKE_CURRENT_BINARY_DIR})
# use the following line to create views with namespaces.
# drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
#                     ${CMAKE_CURRENT_BINARY_DIR} TRUE)

target_include_directories(${PROJECT_NAME}
                           PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
                                   ${CMAKE_CURRENT_SOURCE_DIR}/models)
target_sources(${PROJECT_NAME}
               PRIVATE
               ${SRC_DIR}
               ${CTL_SRC}
               ${FILTER_SRC}
               ${PLUGIN_SRC}
               ${MODEL_SRC})
# ##############################################################################
# uncomment the following line for dynamically loading views
# set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS ON)

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

add_subdirectory(test)
├── CMakeLists.txt
├── config.json
├── controllers
├── filters
├── main.cc
├── models
│   └── model.json
├── plugins
├── test
│   ├── CMakeLists.txt
│   └── test_main.cc
├── third_party
│   └── drogon
│       ├── build
│       ├── build_debug
│       ├── build.sh
│       ├── ChangeLog.md
│       ├── cmake
│       ├── CMakeLists.txt
│       ├── cmake_modules
│       ├── conanfile.txt
│       ├── config.example.json
│       ├── _config.yml
│       ├── CONTRIBUTING.md
│       ├── docker
│       ├── drogon_ctl
│       ├── drogon.jpg
│       ├── examples
│       ├── format.sh
│       ├── lib
│       ├── LICENSE
│       ├── nosql_lib
│       ├── orm_lib
│       ├── README.md
│       ├── README.zh-CN.md
│       ├── README.zh-TW.md
│       ├── test
│       ├── test.sh
│       ├── test_web
│       ├── third_party
│       └── trantor
└── views

Im getting the error :

vagrant@vagrant:~/cpp/test_web/build$ cmake ..
CMake Error at CMakeLists.txt:22 (add_executable):
  The target name "/home/vagrant/cpp/drogon/test_web" is reserved or not
  valid for certain CMake features, such as generator expressions, and may
  result in undefined behavior.


-- use c++17
CMake Error at CMakeLists.txt:52 (drogon_create_views):
  Unknown CMake command "drogon_create_views".


-- Configuring incomplete, errors occurred!
See also "/home/vagrant/cpp/test_web/build/CMakeFiles/CMakeOutput.log".
See also "/home/vagrant/cpp/test_web/build/CMakeFiles/CMakeError.log".

meiry avatar Apr 02 '22 09:04 meiry

you should add drogon subdirectory to your project

add_subdirectory(third_party/drogon)
target_link_libraries(${PROJECT_NAME} PRIVATE drogon)

an-tao avatar Apr 02 '22 13:04 an-tao

it gives me new error: i changed to :

#                                                                                                       │vagrant@vagrant:~/cpp/test_web2/build$ ls -l
# and comment out the following lines                                                                   │total 0
#find_package(Drogon CONFIG REQUIRED)                                                                   │vagrant@vagrant:~/cpp/test_web2/build$ ls -l
find_package(/home/vagrant/cpp/drogon CONFIG REQUIRED)                                                  │total 0
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)                                           │vagrant@vagrant:~/cpp/test_web2/build$ cd ..

gives me this error:

-- Looking for C++ include any - found
-- Looking for C++ include string_view
-- Looking for C++ include string_view - found
-- Looking for C++ include coroutine
-- Looking for C++ include coroutine - not found
CMake Error at CMakeLists.txt:32 (find_package):
  Could not find a package configuration file provided by
  "/home/vagrant/cpp/drogon" with any of the following names:

    /home/vagrant/cpp/drogonConfig.cmake
    /home/vagrant/cpp/drogon-config.cmake

  Add the installation prefix of "/home/vagrant/cpp/drogon" to
  CMAKE_PREFIX_PATH or set "/home/vagrant/cpp/drogon_DIR" to a directory
  containing one of the above files.  If "/home/vagrant/cpp/drogon" provides
  a separate development package or SDK, be sure it has been installed.


-- Configuring incomplete, errors occurred!
See also "/home/vagrant/cpp/test_web/build/CMakeFiles/CMakeOutput.log".
See also "/home/vagrant/cpp/test_web/build/CMakeFiles/CMakeError.log".

those files i can't find

/home/vagrant/cpp/drogonConfig.cmake
/home/vagrant/cpp/drogon-config.cmake

In windows i had to add those lines to the cmakefile :

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20")
set(CMAKE_CXX_STANDARD 20) 
endif(MSVC)

and comment this line

#add_subdirectory(test)

and this line :

#drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
#                    ${CMAKE_CURRENT_BINARY_DIR})

but the sln file created without any include directories in the project files


meiry avatar Apr 02 '22 16:04 meiry

If you have drogon installed in your OS, use the find_package command

find_package(Drogon CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon) 

Or if you want to compile the drogon source code with your application, use the add_subdirectory command.

an-tao avatar Apr 03 '22 03:04 an-tao

this is what i did i have compiled dorgon located in : /home/vagrant/cpp/drogon

vagrant@vagrant:~/cpp$ pwd
**/home/vagrant/cpp**
vagrant@vagrant:~/cpp$ tree -L 1 drogon/
drogon/
├── build
├── build_debug
├── build.sh
├── ChangeLog.md
├── cmake
├── CMakeLists.txt
├── cmake_modules
├── conanfile.txt
├── config.example.json
├── _config.yml
├── CONTRIBUTING.md
├── docker
├── drogon_ctl
├── drogon.jpg
├── examples
├── format.sh
├── lib
├── LICENSE
├── nosql_lib
├── orm_lib
├── README.md
├── README.zh-CN.md
├── README.zh-TW.md
├── test
├── test.sh
├── test_web
├── third_party
└── trantor

meiry avatar Apr 03 '22 05:04 meiry

this is what i did i have compiled dorgon located in : /home/vagrant/cpp/drogon

vagrant@vagrant:~/cpp$ pwd
**/home/vagrant/cpp**
vagrant@vagrant:~/cpp$ tree -L 1 drogon/
drogon/
├── build
├── build_debug
├── build.sh
├── ChangeLog.md
├── cmake
├── CMakeLists.txt
├── cmake_modules
├── conanfile.txt
├── config.example.json
├── _config.yml
├── CONTRIBUTING.md
├── docker
├── drogon_ctl
├── drogon.jpg
├── examples
├── format.sh
├── lib
├── LICENSE
├── nosql_lib
├── orm_lib
├── README.md
├── README.zh-CN.md
├── README.zh-TW.md
├── test
├── test.sh
├── test_web
├── third_party
└── trantor

Did you run make install?

an-tao avatar Apr 03 '22 06:04 an-tao

no i did not , i have the drogon in the development dir why should i do install ?

meiry avatar Apr 03 '22 08:04 meiry

@an-tao
i did what you suggest and run make install but now when i run the make in my test project im getting :

make                                                              │-- Installing: /usr/local/include/trantor/utils/LogStream.h
[ 50%] Building CXX object CMakeFiles/test_web.dir/main.cc.o                                            │-- Installing: /usr/local/include/trantor/utils/Logger.h
In file included from /usr/local/include/drogon/HttpBinder.h:25,                                        │-- Installing: /usr/local/include/trantor/utils/MsgBuffer.h
                 from /usr/local/include/drogon/HttpAppFramework.h:21,                                  │-- Installing: /usr/local/include/trantor/utils/NonCopyable.h
                 from /usr/local/include/drogon/drogon.h:23,                                            │-- Installing: /usr/local/include/trantor/utils/ObjectPool.h
                 from /home/vagrant/cpp/test_web/main.cc:1:                                             │-- Installing: /usr/local/include/trantor/utils/SerialTaskQueue.h
/usr/local/include/drogon/HttpRequest.h:26:10: fatal error: json/json.h: No such file or directory      │-- Installing: /usr/local/include/trantor/utils/TaskQueue.h
   26 | #include <json/json.h>                                                                          │-- Installing: /usr/local/include/trantor/utils/TimingWheel.h
      |          ^~~~~~~~~~~~~                                                                          │-- Installing: /usr/local/include/trantor/utils/Utilities.h
compilation terminated.                                                                                 │-- Installing: /usr/local/lib/cmake/Trantor/TrantorConfig.cmake
CMakeFiles/test_web.dir/build.make:75: recipe for target 'CMakeFiles/test_web.dir/main.cc.o' failed     │-- Installing: /usr/local/lib/cmake/Trantor/TrantorConfigVersion.cmake
make[2]: *** [CMakeFiles/test_web.dir/main.cc.o] Error 1                                                │-- Installing: /usr/local/lib/cmake/Trantor/Findc-ares.cmake
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/test_web.dir/all' failed                         │-- Installing: /usr/local/lib/cmake/Trantor/TrantorTargets.cmake
make[1]: *** [CMakeFiles/test_web.dir/all] Error 2                                                      │-- Installing: /usr/local/lib/cmake/Trantor/TrantorTargets-noconfig.cmake
Makefile:90: recipe for target 'all' failed                                                             │-- Installing: /usr/local/bin/drogon_ctl
make: *** [all] Error 2

looks like it is looking for the jsoncpp header file , isnt included in the cmake ? or am i doing something wrong here ? Thanks

meiry avatar Apr 03 '22 20:04 meiry

If you add drogon by:

find_package(Drogon CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon) 

The dependencies of drogon will be configured automatically.

an-tao avatar Apr 04 '22 02:04 an-tao

now it is working linux , thanks! what about windows ? i dont want to use conan or vcpkg i cloned all the libarary's source code and compiled them ( jsoncpp , c-arais , zlib ) And currently i create the new project and add the link/headers manully . is it pusible to create the package authomatclly that include all the links path's and header paths ?

meiry avatar Apr 04 '22 04:04 meiry