Search code examples
c++visual-studiocmakemayamaya-api

why i have some missing files when cmake generate build folder ? (Maya 2020 - CMake 3.16.4 - VS 2017)


I exactly followed the instruction in API help to create visual studio project: The CMakeLists.txt File guide

but I got this error:

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.

by the way , this error didn't stop the process and CMake generate the build folder for me but as you can see it didn't create some files i think , there are no helloworld.vcxproj & helloworld.vcxproj.filters

Missing Files

FYI : i use Cmake 3.16.4 and visual studio 2017


Solution

  • The tutorial is incomplete, as it is missing the project() command. Your CMake project should always have at least one project() command, as it is used to initialize some pretty essential variables, and the language used in the CMake file, among other things. From the CMake documentation:

    The top-level CMakeLists.txt file for a project must contain a literal, direct call to the project() command; loading one through the include() command is not sufficient. If no such call exists, CMake will issue a warning and pretend there is a project(Project) at the top to enable the default languages (C and CXX).

    Using the set() command to initialize PROJECT_NAME is bad practice, as the project() call also does this for you. I would suggest modifying the CMake file to include the project() command instead:

    cmake_minimum_required(VERSION 2.8)
    
    include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
    
    # Set the project here.
    project(exampleNode)
    
    set(RESOURCES_FILES myResource.xpm)
    
    set(MEL_FILES 
         exampleNode.mel)
    
    set(SOURCE_FILES
         exampleNode.cpp
         ${MEL_FILES}
    )
    
    set(LIBRARIES
        OpenMaya Foundation
    )
    
    find_package(MtoA)
    find_alembic()
    build_plugin()