0

I am trying to build a cross platform school project in C++ with CMake. My project requires the use of the Irrlicht library and must compile under Linux and Windows 10.

The project source path contains a lib folder, containing the Irrlicht header (in an include subfolder), an Irrlicht.dll, an Irrlicht.lib and a FindIrrlicht.cmake module.

I set CMAKE_MODULE_PATH to point to this directory, then call find_package(Irrlicht REQUIRED) in my CMakeLists.txt.

When I try to compile under Linux, everything works fine. However, when I try to run the configuration with CMake (using the CMake GUI) under Windows, the FindIrrlicht.cmake module that I have does not work (it should, since it is provided by the school and they say it should, also I know other people had it work without modifications). I believe that I have identified the cause of the problem, but I do not understance why it occurs nor how to fix it.

FindIrrlicht.cmake looks for the include directory and the Irrlicht.lib (or libIrrlicht.so under Linux, using prefix/suffix options) in some standard Linux include/library path AND under CMAKE_MODULE_PATH. When compiling on Windows, it should find everything in CMAKE_MODULE_PATH. It calls find_library like this:

FIND_LIBRARY(Irrlicht_LIBRARIES
    NAMES
      Irrlicht
    PATHS
      "/usr/lib64/"
      "/usr/lib/"
      "/usr/lib/x86_64-linux-gnu/"
      "/usr/local/lib/"
      "/usr/local/lib64/"
      "${CMAKE_MODULE_PATH}/" #Should find in this path for Windows configuration
      "${Irrlicht_DIR}/"
)

The problem is, the path in CMAKE_MODULE_PATH is correct, since find_path() (see below) is able to find the include directory for Irrlicht. But it sets the Irrlicht_LIBRARIES as NOTFOUND. I verified times and again that the files are there and that the files are in the right place. I also checked the permissions on the files.

IF (NOT Irrlicht_INCLUDE_DIRS OR NOT Irrlicht_LIBRARIES)
  FIND_PATH(Irrlicht_INCLUDE_DIRS
    NAMES
      irrlicht.h
    PATHS
      "/usr/include/irrlicht/"
      "/usr/local/include/irrlicht/"
      "${CMAKE_MODULE_PATH}/include/" #Does find in Windows
      "${Irrlicht_DIR}/include/"
  )

Also, later in the CMakeLists.txt I call a file(COPY "${CMAKE_MODULE_PATH}/Irrlicht.dll" DESTINATION ${EXECUTABLE_OUTPUT_PATH}) successfully, and tried it too with Irrlicht.lib with success. So the path is definitely not the problem here.

Thank you in advance for any help !

P.S.: This is my first time asking a question on StackOverflow, if I did/wrote something not right please let me know, I would be grateful.

  • Also, I forgot to mention but I looked into `CMAKE_FIND_ROOT_PATH` and I tried different combinations, but none worked either, so I believe it won't help. Also, like I mentionned, the FindIrrlicht.cmake module is provided by the school and I should not change it. – Matthieu Rochette Jun 03 '20 at 21:26
  • Does original `FindIrrlicht.cmake` *actually* use [CMAKE_MODULE_PATH](https://cmake.org/cmake/help/v3.16/variable/CMAKE_MODULE_PATH.html) variable in a way you show? This is really **weird usage**: this variable is automatically used by CMake for locate `FindXXX.cmake` scripts and the scripts for `include()`. But it is not intended to be used as `PATHS`/`HINTS` for `find_library` and `find_path`. Moreover, in *general* the variable could contain a **list of paths**, so using it as `"${CMAKE_MODULE_PATH}/include/"` has no sense. – Tsyvarev Jun 03 '20 at 21:45
  • If `FindXXX.cmake` script wants to refer to the directory, whether the script is located, then [CMAKE_CURRENT_LIST_DIR](https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_LIST_DIR.html) variable could fit that purpose very well. – Tsyvarev Jun 03 '20 at 21:48
  • I agree that the use is unconventional, but as I mentioned earlier, this is a school project, and the school provides a "package" that should not be modified which contains the irrlicht library (.dll & .lib) for Windows, and the FindIrrlicht.cmake is in it too. I guess they did it like that in order to make automated testing easier (they use a script to test the validity of the project for each student). – Matthieu Rochette Jun 04 '20 at 09:13
  • Yes, I understand that `FindIrrlicht.cmake` is not written by you and you aren't intended to edit it. It was actually a note (for you and for other readers), that it is better to not use `FindIrrlicht.cmake` script as an *example* of your own scripts of such kind. After all, Stack Overflow is a *learning* site, learning what to do and what to avoid. Once more: my comments by no means intend to tell "you do that wrong". – Tsyvarev Jun 04 '20 at 10:20

1 Answers1

0

Well, I found my problem. I feel stupid for not thinking about this sooner...

The problem was in the pre/suffixes, with some debugging output I realised that they were set for Linux instead of Windows, hence not founding the library file.

The reason for that is that in the CMakeLists.txt, the call to find_package was done before the call to project(), thus the MSVC variables was not set during the call to find_package, which led the script to believe it was called under Linux.