0

I've made a cmake project in viusal studio 2022 where I have 2 projects: Engine and App. When I build it I get a Cannot find Engine.dll error. To fix this I simply move Engine.dll next to App.exe. But I have to do this every time I build it. Here is what my project structure looks like:

[![enter image description here][1]][1]

Engine/CMakeLists.txt:

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/includes)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_definitions(-Dengine_EXPORTS)

# Third-party configurations

file(GLOB SOURCE_FILES 
    src/ImGUI/ImGUI_manager.cpp

    Engine.cpp
)

add_library (Engine SHARED ${IMGUI_BUILD} ${SOURCE_FILES})

target_link_libraries(
    Engine

    PUBLIC

    OpenGL32
)

if (CMAKE_VERSION VERSION_GREATER 3.12)
  set_property(TARGET Engine PROPERTY CXX_STANDARD 20)
endif()

target_include_directories(Engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includes/)

App/CMakeLists.txt:

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../App/includes)

add_executable (App   "main.cpp" "src/Application.cpp")

if (CMAKE_VERSION VERSION_GREATER 3.12)
  set_property(TARGET App PROPERTY CXX_STANDARD 20)
endif()

# find_package(Engine REQUIRED CONFIG PATHS "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(App PRIVATE Engine)

and my CMake on root directory:

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)

# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
  cmake_policy(SET CMP0141 NEW)
  set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

project ("MyProject")

# Include sub-projects.
add_subdirectory("Engine")
add_subdirectory ("App")

How can I configure everything so that I don't have to add Engine.dll next to App.exe manually every time I build the project? [1]: https://i.stack.imgur.com/JGgZC.png

Turgut
  • 711
  • 3
  • 25

0 Answers0