So I have my root CMakeLists.txt
here:
cmake_minimum_required(VERSION 3.16)
project(Vibranium_Core)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost 1.72.0)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
include_directories(${Boost_INCLUDE_DIR})
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
message(STATUS "Target is 64 bits")
if (WIN32)
set(WINXXBITS Win64)
endif(WIN32)
else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
message(STATUS "Target is 32 bits")
if (WIN32)
set(WINXXBITS Win32)
endif(WIN32)
endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(MySQL REQUIRED)
include_directories(${MYSQL_INCLUDE_DIR})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Common)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/WorldServer)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/AuthServer)
add_subdirectory(Tests)
set_target_properties(VibraniumCoreTests PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gtest PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gmock PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gtest_main PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gmock_main PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(
Common WorldServer AuthServer
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
What I want to achieve is both AuthServer
& WorldServer
targets to use shared library called by me Common
. So far so good. I come to a stage where I want to provide mysql functionalities to my Common
library. In order to do that I have to include it in Common
and link the MySQL Connector.
So here is my Common
CMakeLists.txt file contents:
add_library(
Common
SHARED
Config.cpp
Config.h
Logger.cpp
Logger.h
Database/DatabaseLoader.cpp
Database/DatabaseLoader.h
Database/MySQLConnection.h
Database/MySQLConnection.cpp
Database/MySQLTable.h
Database/MySQLTable.cpp
)
if(WIN32)
target_include_directories(Common PUBLIC
${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include
)
# Link the MySQL library to your executable.
target_link_libraries(Common PUBLIC
${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/lib64/vs14/mysqlcppconn8.lib
)
else()
target_link_libraries(Common LINK_PUBLIC ${MYSQL_LIBRARY} mysqlcppconn)
endif()
target_include_directories(Common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
So with this my AuthServer
target builds successfully. However when I try to start it it says:
The code execution cannot proceed because mysqlcppconn8-2-vs14.dll was not found. Reinstalling the program may fix this problem.
In order to make the program run I have to manually copy from here C:\Program Files\MySQL\Connector C++ 8.0\lib64\mysqlcppconn8-2-vs14.dll
into the /bin folder of AuthServer
.
What I want to achive is to force AuthServer
and WorldServer
to look for mysqlcppconn8-2-vs14.dll
inside build_dir/lib
folder instead of the root build directory.
How can I achieve that ?