@@ -14,12 +14,13 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1414
1515set (LIBVIRTUALHID_IS_TOP_LEVEL OFF )
1616if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR )
17- set (LIBVIRTUALHID_IS_TOP_LEVEL ON )
17+ set (LIBVIRTUALHID_IS_TOP_LEVEL ON )
1818endif ()
1919
2020if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
21- message (STATUS "Setting build type to 'Release' as none was specified." )
22- set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE )
21+ message (STATUS "Setting build type to 'Release' as none was specified." )
22+ set (CMAKE_BUILD_TYPE "Release" CACHE STRING
23+ "Choose the type of build." FORCE )
2324endif ()
2425
2526list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR } /cmake" )
@@ -37,22 +38,26 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
3738include (CMakePackageConfigHelpers )
3839include (GNUInstallDirs )
3940
41+ # Copy MinGW runtime DLLs beside a target when using GNU toolchains on Windows.
4042function (libvirtualhid_copy_mingw_runtime target_name )
41- if (NOT WIN32 OR NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
42- return ()
43+ if (NOT WIN32 OR NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
44+ return ()
45+ endif ()
46+
47+ get_filename_component (lvh_compiler_dir "${CMAKE_CXX_COMPILER } " DIRECTORY )
48+ foreach (lvh_runtime_dll IN ITEMS
49+ libgcc_s_seh-1.dll
50+ libstdc++-6.dll
51+ libwinpthread-1.dll)
52+ set (lvh_runtime_path "${lvh_compiler_dir} /${lvh_runtime_dll} " )
53+ if (EXISTS "${lvh_runtime_path} " )
54+ add_custom_command (TARGET "${target_name} " POST_BUILD
55+ COMMAND ${CMAKE_COMMAND } -E copy_if_different
56+ "${lvh_runtime_path} "
57+ "$<TARGET_FILE_DIR :${target_name} >"
58+ COMMENT "Copying MinGW runtime ${lvh_runtime_dll} " )
4359 endif ()
44-
45- get_filename_component (_lvh_compiler_dir "${CMAKE_CXX_COMPILER } " DIRECTORY )
46- foreach (_lvh_runtime_dll IN ITEMS libgcc_s_seh-1.dll libstdc++-6.dll libwinpthread-1.dll)
47- set (_lvh_runtime_path "${_lvh_compiler_dir} /${_lvh_runtime_dll} " )
48- if (EXISTS "${_lvh_runtime_path} " )
49- add_custom_command (TARGET "${target_name} " POST_BUILD
50- COMMAND ${CMAKE_COMMAND } -E copy_if_different
51- "${_lvh_runtime_path} "
52- "$<TARGET_FILE_DIR :${target_name} >"
53- COMMENT "Copying ${_lvh_runtime_dll} to $<TARGET_FILE_DIR :${target_name} >" )
54- endif ()
55- endforeach ()
60+ endforeach ()
5661endfunction ()
5762
5863#
@@ -64,36 +69,36 @@ add_subdirectory(src)
6469# Examples, tests, and docs are top-level only
6570#
6671if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME )
67- if (BUILD_DOCS)
68- add_subdirectory (third-party/doxyconfig docs )
69- endif ()
70-
71- if (BUILD_EXAMPLES)
72- add_subdirectory (examples )
73- endif ()
74-
75- if (BUILD_TESTS)
76- enable_testing ()
77- add_subdirectory (tests )
78- endif ()
72+ if (BUILD_DOCS)
73+ add_subdirectory (third-party/doxyconfig docs )
74+ endif ()
75+
76+ if (BUILD_EXAMPLES)
77+ add_subdirectory (examples )
78+ endif ()
79+
80+ if (BUILD_TESTS)
81+ enable_testing ()
82+ add_subdirectory (tests )
83+ endif ()
7984endif ()
8085
8186#
8287# Package config
8388#
8489configure_package_config_file (
85- "${CMAKE_CURRENT_SOURCE_DIR } /cmake/libvirtualhid-config.cmake.in"
86- "${CMAKE_CURRENT_BINARY_DIR } /libvirtualhid-config.cmake"
87- INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR} /cmake/libvirtualhid"
90+ "${CMAKE_CURRENT_SOURCE_DIR } /cmake/libvirtualhid-config.cmake.in"
91+ "${CMAKE_CURRENT_BINARY_DIR } /libvirtualhid-config.cmake"
92+ INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR} /cmake/libvirtualhid"
8893)
8994
9095write_basic_package_version_file (
91- "${CMAKE_CURRENT_BINARY_DIR } /libvirtualhid-config-version.cmake"
92- VERSION ${PROJECT_VERSION }
93- COMPATIBILITY SameMajorVersion
96+ "${CMAKE_CURRENT_BINARY_DIR } /libvirtualhid-config-version.cmake"
97+ VERSION ${PROJECT_VERSION }
98+ COMPATIBILITY SameMajorVersion
9499)
95100
96101install (FILES
97102 "${CMAKE_CURRENT_BINARY_DIR } /libvirtualhid-config.cmake"
98103 "${CMAKE_CURRENT_BINARY_DIR } /libvirtualhid-config-version.cmake"
99- DESTINATION "${CMAKE_INSTALL_LIBDIR} /cmake/libvirtualhid" )
104+ DESTINATION "${CMAKE_INSTALL_LIBDIR} /cmake/libvirtualhid" )
0 commit comments