I have no idea what I did; I am trying to compile C++ code and CMake on CLion chooses the Visual Studio C compiler to compile it. When I don’t use CMake, it runs fine.
main.cpp:
#include <iostream>
#include "include/Window.hpp"
int main()
{
Window * window = new Window();
return 0;
}
Window.hpp:
#ifndef WINDOW_HPP
#define WINDOW_HPP
class Window
{
public:
Window();
};
#endif //WINDOW_HPP
Window.cpp is empty
CMakeLists.txt:
cmake_minimum_required( VERSION 3.16 )
set( CMAKE_CXX_STANDARD 14 )
project( myProject )
include( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/App.cmake" )
set( SOURCES
main.cpp
src/Window.cpp
include/Window.hpp
)
make_app(
SOURCES ${SOURCES}
)
App.cmake:
include( CMakeParseArguments )
set( USED_PATH "../" )
function( make_app )
# parse arguments that come through function
set( oneValueArgs NAME PATH)
set( multiValueArgs SOURCES INCLUDES LIBRARIES )
cmake_parse_arguments( ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
# make sure name is set for app
if( NOT ARG_NAME )
set( ARG_NAME "${PROJECT_NAME}" )
endif()
# set path
if( ARG_PATH )
set( USED_PATH ${ARG_PATH} )
endif()
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/include" )
# setup GLAD
include_directories( "extern/glad/include" )
list( APPEND PROJECT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/extern/glad/include/glad/glad.h" )
list( APPEND PROJECT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/extern/glad/src/glad.c" )
# setup GLFW
find_package( OpenGL REQUIRED )
include_directories( "extern/glfw/include" )
include_directories( ${OPENGL_INCLUDE_DIRS} )
set( GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE )
set( GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE )
set( GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
set( GLFW_BUILD_INSTALL OFF CACHE BOOL "GLFW lib only" FORCE )
add_subdirectory( extern/glfw )
# add argument sources to project sources
list( APPEND PROJECT_SOURCES ${ARG_SOURCES} )
# the executable, using the argument name and project sources
add_executable( ${ARG_NAME} ${PROJECT_SOURCES} )
target_link_libraries( ${ARG_NAME} ${OPENGL_LIBRARIES} glfw ${GLFW_LIBRARIES} )
endfunction()
That is actually all the code I have. I have a feeling that somewhere in App.cmake this is causing this issue.
Would anyone mind to explain why this is happening and how to fix it?