简体   繁体   中英

How to prevent CMake adding CMakeLists.txt at root of generated project?

I have the following CMakeLists.txt :

cmake_minimum_required(VERSION 3.15.5)

project(REminiscence VERSION 0.4.5)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

configure_file(REminiscenceConfig.h.in REminiscenceConfig.h)

add_definitions(-DUSE_MODPLUG -DUSE_STATIC_SCALER -DUSE_TREMOR -DUSE_ZLIB)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(RE_SRC
    "collision.cpp"
    "cpc_player.cpp"
    "cutscene.cpp"
    "decode_mac.cpp"
    "dynlib.cpp"
    "file.cpp"
    "fs.cpp"
    "game.cpp"
    "graphics.cpp"
    "main.cpp"
    "menu.cpp"
    "mixer.cpp"
    "mod_player.cpp"
    "ogg_player.cpp"
    "piege.cpp"
    "protection.cpp"
    "resource.cpp"
    "resource_aba.cpp"
    "resource_mac.cpp"
    "scaler.cpp"
    "screenshot.cpp"
    "seq_player.cpp"
    "sfx_player.cpp"
    "staticres.cpp"
    "systemstub_sdl.cpp"
    "unpack.cpp"
    "util.cpp"
    "video.cpp"
)

source_group("Sources" FILES ${RE_SRC})

set(RE_INC
    "cpc_player.h"
    "cutscene.h"
    "decode_mac.h"
    "dynlib.h"
    "file.h"
    "fs.h"
    "game.h"
    "graphics.h"
    "intern.h"
    "menu.h"
    "mixer.h"
    "mod_player.h"
    "ogg_player.h"
    "resource.h"
    "resource_aba.h"
    "resource_mac.h"
    "scaler.h"
    "screenshot.h"
    "seq_player.h"
    "sfx_player.h"
    "systemstub.h"
    "unpack.h"
    "util.h"
    "video.h"
)

source_group("Headers" FILES ${RE_INC})

add_executable(REminiscence ${RE_SRC} ${RE_INC})

find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(REminiscence PRIVATE SDL2::SDL2 SDL2::SDL2main)

find_package(ZLIB REQUIRED)
target_link_libraries(REminiscence PRIVATE ZLIB::ZLIB)

target_include_directories(REminiscence PUBLIC
    "${PROJECT_BINARY_DIR}"
)

When I generate the Visual Studio solution, it also puts CMakeLists.txt at the root:

在此处输入图像描述

Question

How, if possible, to prevent CMake adding that CMakeLists.txt at root?

You can't remove CMakeLists.txt from a project, it's done by design.

cmake adds CMakeLists.txt to a project as a dependence. If you modify it even in an external editor, MSBuild runs cmake. to update a project. You don't need to run cmake. and cmake --build manually, the Visual Studio does it for you when you select Build Solution .

Also if CMakeLists.txt is in a project, you can easy edit it in Visual Studio directly.

Side note: if you want the CMakeLists.txt entry to appear in another "folder" than the project's root, simply add a "CMakeLists.txt" entry to the respective source_group variable. CMakeLists.txt will still be a depenency, but will be listed under the chosen folder in Visual Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM