mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
place dlls in the same directory as the executables on msvc
This commit is contained in:
parent
8a0f87406b
commit
90c5055b77
@ -129,6 +129,14 @@ if(SPDLOG_BUILD_SHARED)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
# place dlls in the same directory as the executables on msvc
|
||||
if(BUILD_SHARED_LIBS AND MSVC)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||
endif()
|
||||
|
||||
message(STATUS "spdlog version: ${SPDLOG_VERSION}")
|
||||
message(STATUS "spdlog build type: " ${CMAKE_BUILD_TYPE})
|
||||
message(STATUS "spdlog build shared: " ${BUILD_SHARED_LIBS})
|
||||
@ -255,8 +263,9 @@ if(BUILD_SHARED_LIBS)
|
||||
add_library(spdlog SHARED ${SPDLOG_SRCS} ${SPDLOG_HEADERS} ${VERSION_RC})
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
|
||||
if(MSVC)
|
||||
# disable dlls related warnings on msvc
|
||||
target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
|
||||
/wd4275>)
|
||||
/wd4275>)
|
||||
endif()
|
||||
else()
|
||||
add_library(spdlog STATIC ${SPDLOG_SRCS} ${SPDLOG_HEADERS})
|
||||
|
@ -10,6 +10,7 @@ endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(benchmark CONFIG)
|
||||
|
||||
if(NOT benchmark_FOUND)
|
||||
message(STATUS "Using CMake Version ${CMAKE_VERSION}")
|
||||
# User can fetch googlebenchmark
|
||||
@ -35,9 +36,3 @@ target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::spdlog)
|
||||
|
||||
add_executable(formatter-bench formatter-bench.cpp)
|
||||
target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::spdlog)
|
||||
|
||||
# copy dlls to the executable folder for msvc
|
||||
if(MSVC AND (SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS))
|
||||
add_custom_command(TARGET latency POST_BUILD COMMAND ${CMAKE_COMMAND}
|
||||
-E copy_if_different $<TARGET_FILE:spdlog> $<TARGET_FILE:fmt> $<TARGET_FILE:benchmark::benchmark> $<TARGET_FILE_DIR:latency>)
|
||||
endif()
|
||||
|
@ -1,5 +1,10 @@
|
||||
include(FetchContent)
|
||||
|
||||
# Always build static fmtlib version
|
||||
set(BUILD_SHARED_LIBS_ORIG "${BUILD_SHARED_LIBS}")
|
||||
#set(BUILD_SHARED_LIBS OFF CACHE BOOL "Disable BUILD_SHARED_LIBS for fmtlib" FORCE)
|
||||
|
||||
Set(FETCHCONTENT_QUIET FALSE)
|
||||
FetchContent_Declare(
|
||||
fmt
|
||||
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
|
||||
@ -9,10 +14,11 @@ FetchContent_Declare(
|
||||
|
||||
FetchContent_GetProperties(fmt)
|
||||
if(NOT fmt_POPULATED)
|
||||
message(STATUS "Fetching fmt lib...")
|
||||
FetchContent_Populate(fmt)
|
||||
# We do not require os features of fmt
|
||||
set(FMT_OS OFF CACHE BOOL "Disable FMT_OS" FORCE)
|
||||
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR})
|
||||
endif ()
|
||||
|
||||
# Restore BUILD_SHARED_LIBS
|
||||
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_ORIG}" CACHE BOOL "Restore BUILD_SHARED_LIBS" FORCE)
|
@ -9,10 +9,4 @@ if(NOT TARGET spdlog)
|
||||
endif()
|
||||
|
||||
add_executable(example example.cpp)
|
||||
target_link_libraries(example PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
|
||||
|
||||
# copy dlls to the executable folder for msvc
|
||||
if(MSVC AND (SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS))
|
||||
add_custom_command(TARGET example POST_BUILD COMMAND ${CMAKE_COMMAND}
|
||||
-E copy_if_different $<TARGET_FILE:spdlog> $<TARGET_FILE:fmt> $<TARGET_FILE_DIR:example>)
|
||||
endif()
|
||||
target_link_libraries(example PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
|
@ -87,11 +87,4 @@ endfunction()
|
||||
|
||||
if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
|
||||
spdlog_prepare_test(spdlog-utests spdlog::spdlog)
|
||||
|
||||
# copy dlls to the executable folder for msvc
|
||||
if(MSVC AND (SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS))
|
||||
add_custom_command(TARGET spdlog-utests POST_BUILD COMMAND ${CMAKE_COMMAND}
|
||||
-E copy_if_different $<TARGET_FILE:spdlog> $<TARGET_FILE:fmt> $<TARGET_FILE:Catch2::Catch2> $<TARGET_FILE:Catch2::Catch2WithMain> $<TARGET_FILE_DIR:spdlog-utests>)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user