Во-первых, я хочу сказать, что это не дубликат Сделать ссылки, такие как Visual Studio в CMake
Я просматриваю inte rnet и не вижу, что сопоставляется с Visual Studio проектные ссылки в CMake. Я нашел эту страницу CMake и Visual Studio , но ссылок там нет. Итак, это моя папка config:
- CMakeLists.txt
- demo/
----CMakeLists.txt
- engine/
----CMakeLists.txt
- bin/
----[config]/
------[target_name]
Демонстрационный проект - это dll, а движок - exe, и я хочу добавить движок как ссылку в dll, поэтому, когда я компилирую dll, он компилируется exe, если были внесены изменения.
Main CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
cmake_policy(SET "CMP0079" NEW)
# set configuration types and make them advanced option on cmake.
mark_as_advanced(CMAKE_INSTALL_PREFIX)
set(CMAKE_CONFIGURATION_TYPES Release Debug Release_Asserts)
set(CMAKE_CXX_FLAGS_RELEASE_ASSERTS ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_ASSERTS ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
# set c++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# set the project/solution name
project("Llamathrust Engine"
VERSION 1.0
DESCRIPTION "Game engine Win32"
LANGUAGES C CXX)
# use folders for ZERO_CHECK and BUILD_ALL
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# add glad library
add_subdirectory("${CMAKE_SOURCE_DIR}/external/glad")
# add glm library
add_subdirectory("${CMAKE_SOURCE_DIR}/external/glm")
# add the engine to the solution
add_subdirectory("${CMAKE_SOURCE_DIR}/llamathrust/")
target_include_directories("llamathrust" PRIVATE "${CMAKE_SOURCE_DIR}/external/opengl/include")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT llamathrust)
# link llamathrust to GLAD
target_link_libraries("llamathrust" "glad")
# link llamathrust to GLM
target_link_libraries("llamathrust" "glm")
target_include_directories("llamathrust" PUBLIC "${CMAKE_SOURCE_DIR}/external/glm")
# add the demo code to the solution
add_subdirectory("${CMAKE_SOURCE_DIR}/demo/")
# link demo and llamathrust
# link llamathrust to GLM
target_link_libraries("demo" "glm")
target_include_directories("demo" PUBLIC "${CMAKE_SOURCE_DIR}/external/glm")
# remove ...
remove_definitions(/CMAKE_INTDIR)
# adding options
# option to include a blank screen game
#if (BLANK_TARGET)
#endif()
# option to include the demo game
#if (DEMO_TARGET)
#add_subdirectory("${CMAKE_SOURCE_DIR}/demo/")
#endif()
Демо CMakeLists
cmake_minimum_required(VERSION 3.10)
# set the target/project name
set(TARGET_NAME "demo")
# set c++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# set output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/${TARGET_NAME}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/${TARGET_NAME}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/${TARGET_NAME}")
# add preprocessor definitions
add_definitions(-DLT_DYNAMIC_LIB)
# set sources
set(Demo_SRC
main/main_local.hpp
main/main_local.cpp
main/local_imports.hpp
platform/main.cpp
games/game_demo.hpp
games/game_demo.cpp
)
# executable name
add_library(${TARGET_NAME} SHARED ${Demo_SRC})
# set filters
foreach(_source IN ITEMS ${Demo_SRC})
# Get the directory of the source file
get_filename_component(_source_path "${_source}" PATH)
# Make sure we are using windows slashes
string(REPLACE "/" "\\" _group_path "${_source_path}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
set_target_properties(${TARGET_NAME} PROPERTIES PROJECT_LABEL ${TARGET_NAME})
set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
# set include directory to itself
target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(${TARGET_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/llamathrust/include")
# make a reference to the engine
Engine CMakeLists
cmake_minimum_required(VERSION 3.1)
set(TARGET_NAME "llamathrust")
# set output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/${TARGET_NAME}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/${TARGET_NAME}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/${TARGET_NAME}")
# set sources
set(Llamathrust_SRC
...
)
find_package(OpenGL REQUIRED)
# executable name
add_executable(${TARGET_NAME} ${Llamathrust_SRC})
# set filters
foreach(_source IN ITEMS ${Llamathrust_SRC})
# Get the directory of the source file
get_filename_component(_source_path "${_source}" PATH)
# Make sure we are using windows slashes
string(REPLACE "/" "\\" _group_path "${_source_path}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
# find and link to opengl
target_link_libraries(${TARGET_NAME} ${OPENGL_LIBRARY})
target_include_directories(${TARGET_NAME} PRIVATE "${OPENGL_INCLUDE_DIR}")
set(LIBS XInput)
target_link_libraries(${TARGET_NAME} ${LIBS})
# set include directory to itself
target_include_directories(${TARGET_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
# target name label
set_target_properties(${TARGET_NAME} PROPERTIES PROJECT_LABEL ${TARGET_NAME})
#preprocessor definitions
# DEBUG
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY
COMPILE_DEFINITIONS $<$<CONFIG:Debug>:LT_DEBUG>)
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY
COMPILE_DEFINITIONS $<$<CONFIG:Debug>:LT_ENABLE_ASSERTS>)
#RELEASE_ASSERT
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY
COMPILE_DEFINITIONS $<$<CONFIG:Release_Asserts>:LT_RELEASE>)
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY
COMPILE_DEFINITIONS $<$<CONFIG:Release_Asserts>:LT_ENABLE_ASSERTS>)
#RELEASE
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY
COMPILE_DEFINITIONS $<$<CONFIG:Release>:LT_RELEASE>)
Заранее спасибо!