首先,我是CMake的新手。CMake在Visual Studio下构建问题
文件夹结构
root_project
|─── CMakeLists.txt
|─── build
|─── Project 1
| |─── build
| | |─── Debug
| | └─── Release
| |─── CMakeLists.txt
| |─── source
| | └─── include
| |─── resource
| └─── header
└─── Project 2
|─── build
| |─── Debug
| └─── Release
|─── source
| |─── CMakeLists.txt
| └─── include
|─── resource
└─── header
CMake的文件
的的CMakeLists.txt为root_project:
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)
# Project's name
project("RootProject X")
IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt.")
ENDIF()
OPTION(BUILD_TESTS "Decides whether the unit tests will be built." ON)
# C/C++ languages required.
enable_language(C)
enable_language(CXX)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Only allow 64bit architecture
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64bit
message(STATUS "Compiling for x86-64 platform. Proceeding...")
ELSEIF(CMAKE_SIZEOF_VOID_P EQUAL 4)
# 32bit
message(FATAL_ERROR "Compiling for x86 platform. This is not supported. Aborting...")
ELSE()
# unidentified architecture
message(FATAL_ERROR "Running on unidentified architecture. This is not supported. Aborting...")
ENDIF()
# Abort when OpenGL is not found
FIND_PACKAGE(OpenGL 4.5 REQUIRED)
IF(NOT VULKAN_FOUND)
message(WARNING "Could not find Vulkan library.")
ENDIF()
# Add the modules
add_subdirectory("Project 1")
add_subdirectory("Project 2")
的CMakeLists项目1:
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)
project("Project 1")
# Set the version number of the project here
set(VERSION_MAJOR "0")
set(VERSION_MINOR "1")
set(VERSION_PATCH "0")
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
find_package(OpenGL 4.5 REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sources/third-party-include/)
link_libraries(${OPENGL_gl_LIBRARY})
add_definitions(${OpenGL_DEFINITIONS})
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sources/include/)
# ToDo: Testing
set(HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/sources/include/Engine.h
)
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/source/Engine.cpp
)
source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES})
if(WIN32)
# currently add_executable for testing purpose
add_executable("Project 1" WIN32
#${HEADERS}
${SOURCES}
)
ELSEIF(UNIX AND NOT APPLE)
add_library("Project 1"
${HEADERS}
${SOURCES}
)
ELSE()
# The system is not supported
message(FATAL_ERROR "System not supported.")
ENDIF()
target_link_libraries(DarkEngine ${OPENGL_gl_LIBRARY})
的CMakeLists为项目2 :
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)
project("Project 2")
# Set the version number of the project here
set(VERSION_MAJOR "0")
set(VERSION_MINOR "1")
set(VERSION_PATCH "0")
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(HEADERS
)
set(SOURCES
)
source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES})
add_executable("Project 2" WIN32
${HEADERS}
${SOURCES}
)
target_link_libraries("Project 2" "Project 1")
问题/问题
注:我试图实现外的源代码编译,其中重点项目1是从项目2
命令我使用的引擎下root_project的构建运行:cmake .. -G "Visual Studio 15 2017 Win64"
- 项目2对项目1 没有链接210
- 项目2不VS显示2017年
- 我自己的头文件在/包括项目1将显示在外部相关性在2017年VS而非源代码
在CMake的<-> VS方面的项目=解决方案和目标=项目 – tambre
虽然我想提一提,我喜欢的质量这个问题。保持良好的工作! :) – tambre
我总是尝试构建我的帖子以获得更高的质量。所以,根据您的评论,我应该怎样做才能解决我的问题? – ShadowDragon