pupnp / pupnp

libupnp: Build UPnP-compliant control points, devices, and bridges on several operating systems.
https://pupnp.github.io/pupnp
BSD 3-Clause "New" or "Revised" License
352 stars 117 forks source link

Error messages from cmake on clone #258

Closed ingo-h closed 3 years ago

ingo-h commented 3 years ago

Hi @Vollstrecker, from the last synchronization of my pupnp clone I get error messages from cmake that I do not understand: https://github.com/ingo-h/pupnp/actions/runs/655964097. I had compiled googletest and googlemock using make to work with it. To be up to date then I have pulled the library to my local git repository from upstream master https://github.com/pupnp/pupnp.git and pushed it to my github clone. There I get the error messages. Can you help with it?

Vollstrecker commented 3 years ago

You merged master into your branch, so you still have the old version of downloading and include googletest twice.

ingo-h commented 3 years ago

Ah - thank you, will have attention to it next time.

ingo-h commented 3 years ago

Hello @Vollstrecker,

I have taken a new local clone from the library from scratch. If I enter directory pupnp and execute cmake . I do not get googletest and googlemock. What I'm doing wrong?

Vollstrecker commented 3 years ago

Download of additional components must always be activated, as most people want to use what they installed with their package-manager. So either install the googletest dev packages from your distro, or set DOWNLOAD_AND_BUILD_DEPS to true. That's what I meant with "uncoditional download" in my first review.

ingo-h commented 3 years ago

Just found it at https://github.com/pupnp/pupnp#107-cmake-build. Known options have the same meaning as stated in point 5.2 but I cannot find point 5.2 on that page. Where to set DOWNLOAD_AND_BUILD_DEPS to true? Do I have also to set BUILD_TESTING?

Vollstrecker commented 3 years ago

Yep, it's 10.2. If you use cmake -LH you'll get a list of the options with their current values, or you use cmake-gui (I prefer that) or ccmake to see everything possible.

BUILD_TESTING default to on.

ingo-h commented 3 years ago

cmake -LH is a useful command. With the option given at the README I tried:

~$ cmake . -DDOWNLOAD_AND_BUILD_DEP=true

and get:

CMake Warning:
  Manually-specified variables were not used by the project:

    DOWNLOAD_AND_BUILD_DEP

The typo should be corrected to DOWNLOAD_AND_BUILD_DEPS. The point 5.2 should also corrected and I suggest to add an example to use the option similar to that above. But whatever options I use, e.g.

~$ cmake . -DDOWNLOAD_AND_BUILD_DEPS=ON -DBUILD_TESTING=ON

I do not get googletest and googlemock.

Vollstrecker commented 3 years ago

Why do you think you don't get gtest? If you don't get any error while the cmake run, everything is fine. If you want to make sure, type make help to see if gmock and gtest are listed as targets.

ingo-h commented 3 years ago

Why do you think you don't get gtest?

Because nothing is documented. I was looking for the downloaded subdir pupnp/googletest-src (found it now in _deps/). After running make I find the test libraries in pupnp/lib but still don't understand how to run the tests. I'm just looking at it and get an idea step by step.

Vollstrecker commented 3 years ago

That's not documented, as no-one needs to know. I startet CmDaB to get these dependencies in a defined way. You just say "I want to use googletest", and then you use it. Maybe I decide at some point to download to CmDaB/ instead of _deps/, maybe just into dirs at Build_dir direct. For the projects that use it, it just doesn't matter, they order the lib, they use the lib.

And for running the tests, look at gtest/CMakeLists.txt.

In line 3 The test-executable with it's sources is defined.

In line 6 you tell cmake which dirs need to be searched for headers in addition to the dirs that where the headers of the libs you link against are located, because this information is provided by the libs.

In line 10 you tell cmake which libs are needed for linking.

In line 15 a macro is called that reads the tests that are actually run by your executable, so they are listed as separate test instead of just that one file.

After that this repeats for the static version. It seems that you learned bash and the compiler-params, and how to use gtest and mock. cmake is well documented and much easier than any of the listed. Just check https://cmake.org/documentation if you don't understand from the function name what happens or is expected, the search function there is great, and most IDE's give you docs as tooltips for that.

ingo-h commented 3 years ago

Thanks for the details. What commands have I to use to run the test_template.cpp and get this output?

[==========] Running 2 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 1 test from EmptyTestSuite
[ RUN      ] EmptyTestSuite.empty_gtest
[       OK ] EmptyTestSuite.empty_gtest (0 ms)
[----------] 1 test from EmptyTestSuite (0 ms total)

[----------] 1 test from EmptyFixtureTestSuite
[ RUN      ] EmptyFixtureTestSuite.empty_gtest_with_fixture
[       OK ] EmptyFixtureTestSuite.empty_gtest_with_fixture (0 ms)
[----------] 1 test from EmptyFixtureTestSuite (0 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 2 test suites ran. (0 ms total)
[  PASSED  ] 2 tests.

Maybe you can just put an example to run the test-template with one of the next commits? Just using cmake . gives me this:

gtest $ cmake .
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.18)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
CMake Warning (dev) at CMakeLists.txt:19 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "test-upnp-upnpapi-static" links to target "GTest::gmock" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:19 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "test-upnp-upnpapi-static" links to target "UPNP::Static" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:3 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "test-upnp-upnpapi" links to target "GTest::gmock" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:3 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "test-upnp-upnpapi" links to target "UPNP::Shared" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /home/ingo/devel/pupnp-dev/pupnp/gtest
Vollstrecker commented 3 years ago

That depends on your test-file, This function simply run " --gtest_list_tests" and then create a test for every one. From your output I guess your tests are named like the output with the RUN and OK in front. For running the test, there is another programm called ctest which most propably was installed with cmake on your system. This one has it's own options which it will present you.

And no, I'm not going to document how to write or understand CMakeLists.txt's, or how to use ctest if "make test" gives to much output. This is a task for cmake which they really did great. It's the same thing as gtest documents how their stuff works, and here only specific informations for testing upnp-functionality will be given. Otherwise we would have to document autotools/libtool also, plus doxgen, gcc, MS-VS, XCode and maybe C itself.