samedi 3 mars 2018

CLion does not recognize project as C++14

I have been working on a personal project using CMake for some months. Previously, I was using a command-line centered approach (editing the code in an editor like Geany and then building using make), and thus I built my own CMakeLists.txt around my projects. My project has a root CMakeLists.txt that states the C++ standard used is C++14, with set(CMAKE_CXX_STANDARD 14) and set(CMAKE_CXX_STANDARD_REQUIRED ON), and adds the subprojects present in some subfolders.

Some time ago, I decided to try CLion, because of its various features. I imported the project into CLion (without letting it overwrite my CMakeLists.txt) and I am very satisfied with it until now. However, even though the newest versions of CLion state explicit support for C++14, the code analyzer still has problem with method type deductions (i.e. auto methods), which it deduces as void. My code anyway compiles fine and cleanly, because it uses my Clang installed toolchain.

My main CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.9)

project(ReboundTheGame)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install)
set(SFML_STATIC_LIBRARIES ON)

set(COMMONS_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/Commons)

if(MSVC)
    add_definitions(-D_USE_MATH_DEFINES -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4244)
endif()

add_subdirectory(CppMunk)
add_subdirectory(ExportTools)
add_subdirectory(MainGame)
add_subdirectory(Languages)
add_subdirectory(Resources)

add_custom_target(install_everything
    "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target install
    DEPENDS MainGame Languages Resources
    COMMENT "Installing ${PROJECT_NAME}")

Interestingly enough, I created a blank C++14 from CLion to test its functionalities, and its CMakeLists.txt has the exact same command I used on my project's one:

cmake_minimum_required(VERSION 3.9)
project(TestProject)    

set(CMAKE_CXX_STANDARD 14) // what's the difference??

add_executable(TestProject main.cpp)

Yet CLion manages to correct infer the types of auto methods I use in the code.

So far, I have not delved into the .idea folders of both to discover what is wrong, but I am out of ideas now on how to solve this problem. I suppose this might be a mis-configuration of the project, so if anyone needs it, I can attach an archive of my stored folder for you to examine. I am using Ubuntu 17.10, set my cc to clang and my c++ to clang++.

Aucun commentaire:

Enregistrer un commentaire