Search code examples
windowsvisual-studio-codecmakemsys2luajit

Cmake Can´t find luajit packages of msys2 (windows)


I got another Problem with including libs into my cmake Project. The Project specs are:

IDE: Visual Studio Code

Kit: GCC 10.3.0 Mingw64 (via msys2)

The two packages, Freetype and Luajit, are installed via msys (in mingw64 mode), too.

So, this is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)

project(TileGameStudio_Runtime CXX)

set(CMAKE_CXX_FLAGS -v)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(PROJ_SRC
    ${PROJECT_SOURCE_DIR}/src
)

file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS
    ${PROJ_SRC}/*.cpp
)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}\\Game")
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}\\Game")

INCLUDE(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
pkg_check_modules(SDL2_MIXER REQUIRED SDL2_mixer)
find_package(OpenGL REQUIRED)
find_package(Freetype REQUIRED)
find_package(Lua51 REQUIRED)

if(NOT FREETYPE_FOUND)
  message(STATUS "freetype2:   NO")
else()
  message(STATUS "freetype2:   YES..   Version:${FREETYPE_VERSION_STRING}")
endif()

if(NOT LUA_FOUND)
  message(STATUS "LuaJit:   NO")
else()
  message(STATUS "LuaJit:   YES..   Version:${LUA_VERSION_MAJOR }  and Patched: ${LUA_VERSION_PATCH }")
endif()

include_directories(
    ${SDL2_INCLUDE_DIRS}
    ${SDL2_IMAGE_INCLUDE_DIRS}
    ${SDL2_TTF_INCLUDE_DIRS}
    ${SDL2_MIXER_INCLUDE_DIRS}
    ${OPENGL_INCLUDE_DIRS}
    ${LUA_INCLUDE_DIR}
    ${FREETYPE_INCLUDE_DIRS}
)

link_directories (
    ${SDL2_LIBRARY_DIRS}
    ${SDL2_IMAGE_LIBRARY_DIRS}
    ${SDL2_TTF_LIBRARY_DIRS}
    ${SDL2_MIXER_LIBRARY_DIRS}
    ${OPENGL_LIBRARY_DIRS}
    ${LUA_INCLUDE_DIR}
    ${FREETYPE_INCLUDE_DIRS}
)

# add the executable
add_executable(TileGameStudio_Runtime
    ${PROJECT_SOURCES}
)

target_link_libraries (TileGameStudio_Runtime 
    ${SDL2_LIBRARIES}
    ${SDL2_IMAGE_LIBRARIES}
    ${SDL2_TTF_LIBRARIES}
    ${SDL2_MIXER_LIBRARIES}
    ${OPENGL_gl_LIBRARY}
    ${LUA_LIBRARIES}
)

set_target_properties(
    TileGameStudio_Runtime
    PROPERTIES
        OUTPUT_NAME "Game"
        SUFFIX ".exe"
)

And this, is my whole main.cpp:

#include <ft2build.h>
#include FT_FREETYPE_H
#include <iostream>
#include <vector>
#include <string>
#include <assert.h>
#include <SDL2/SDL.h>
#include <SDL2/sdl_ttf.h>
#include <SDL2/SDL_opengl.h>
#include <GL/gl.h>
#include <lua.h>


#ifdef main
#undef main
#endif /* main */

using namespace std;

#define WinWidth 1280
#define WinHeight 720

int main(int argc, char *argv[])
{
    SDL_Window *window = NULL;
    SDL_Renderer *renderer = NULL;

    SDL_Init(SDL_INIT_VIDEO);
    TTF_Init();

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    uint32_t windowFlags = SDL_WINDOW_OPENGL;
    window = SDL_CreateWindow("Runtime", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WinWidth, WinHeight, windowFlags);
    assert(window);
    SDL_GLContext Context = SDL_GL_CreateContext(window);

    bool Running = true;
    bool FullScreen = false;
    while (Running)
    {
        SDL_Event Event;
        while (SDL_PollEvent(&Event))
        {
            if (Event.type == SDL_KEYDOWN)
            {
                switch (Event.key.keysym.sym)
                {
                case SDLK_ESCAPE:
                    Running = 0;
                    break;
                case 'f':
                    FullScreen = !FullScreen;
                    if (FullScreen)
                    {
                        SDL_SetWindowFullscreen(window, windowFlags | SDL_WINDOW_FULLSCREEN_DESKTOP);
                    }
                    else
                    {
                        SDL_SetWindowFullscreen(window, windowFlags);
                    }
                    break;
                default:
                    break;
                }
            }
            else if (Event.type == SDL_QUIT)
            {
                Running = 0;
            }
        }

        glViewport(0, 0, WinWidth, WinHeight);
        glClearColor(0.f, 0.f, 0.f, 0.f);
        glClear(GL_COLOR_BUFFER_BIT);

        SDL_GL_SwapWindow(window); //Update Window Context
    }
    return 0;
}

And this, is my whole Project Structure for now:

1

The Project is not able to find and open lua.h. (file can not be opened)

The installed Luajit Version is:

mingw64/mingw-w64-x86_64-luajit 2.1.0_beta3-2 [installed]
    Just-in-time compiler and drop-in replacement for Lua 5.1 (mingw-w64)

And this is the cmake output:

[main] Configuring folder: TileGameStudio_Runtime 
[proc] Executing command: C:\msys64\mingw64\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-g++.exe -He:/Game_Design/TileGameStudio/TileGameStudio_Runtime -Be:/Game_Design/TileGameStudio/TileGameStudio_Runtime/CMakeBuild -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at C:/msys64/mingw64/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake]   Could NOT find Lua51 (missing: LUA_INCLUDE_DIR)
[cmake] Call Stack (most recent call first):
[cmake]   C:/msys64/mingw64/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
[cmake]   C:/msys64/mingw64/share/cmake-3.20/Modules/FindLua51.cmake:80 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
[cmake]   CMakeLists.txt:30 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "E:/Game_Design/TileGameStudio/TileGameStudio_Runtime/CMakeBuild/CMakeFiles/CMakeOutput.log".

2


Solution

  • I found an Answer for myself. It seems like the Errors appear randomly. After relaunching Vscode 2-3 times, the errors appear or do not appear randomly. Seems like a problem with the IDE 😐