diff --git a/CMakeLists.txt b/CMakeLists.txt index c556347..1d6106d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,22 @@ cmake_minimum_required(VERSION 3.4) project( snoretoast VERSION 0.5.99) option(BUILD_EXAMPLES "Whether to build the examples" OFF) +option(BUILD_STATIC_RUNTIME "Whether link statically to the msvc runtime" ON) include(GenerateExportHeader) set(CMAKE_CXX_STANDARD 17) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) add_subdirectory(data) add_subdirectory(src) if (BUILD_EXAMPLES) add_subdirectory(examples) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2160ead..0823263 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,37 +1,45 @@ +if (BUILD_STATIC_RUNTIME) + #link runtime static + if(MSVC) + foreach(_bt DEBUG RELEASE RELWITHDEBINFO) + string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_${_bt} ${CMAKE_CXX_FLAGS_${_bt}}) + endforeach(_bt DEBUG RELEASE RELWITHDEBINFO) + endif(MSVC) +endif() add_library(SnoreToastActions INTERFACE) target_include_directories(SnoreToastActions INTERFACE $ $ ) add_library(SnoreToast::SnoreToastActions ALIAS SnoreToastActions) add_library(libsnoretoast STATIC snoretoasts.cpp toasteventhandler.cpp linkhelper.cpp utils.cpp) target_link_libraries(libsnoretoast PUBLIC runtimeobject shlwapi SnoreToast::SnoreToastActions) target_compile_definitions(libsnoretoast PRIVATE UNICODE _UNICODE __WRL_CLASSIC_COM_STRICT__ WIN32_LEAN_AND_MEAN NOMINMAX) target_compile_definitions(libsnoretoast PRIVATE SNORETOAST_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} SNORETOAST_VERSION_MINOR=${PROJECT_VERSION_MINOR} SNORETOAST_VERSION_PATCH=${PROJECT_VERSION_PATCH} ) target_compile_definitions(libsnoretoast PUBLIC __WRL_CLASSIC_COM_STRICT__) target_include_directories(libsnoretoast PUBLIC $) set_target_properties(libsnoretoast PROPERTIES EXPORT_NAME LibSnoreToast) add_library(SnoreToast::LibSnoreToast ALIAS libsnoretoast) generate_export_header(libsnoretoast) add_executable(SnoreToast WIN32 main.cpp ${SNORE_TOAST_DEPS}) target_link_libraries(SnoreToast SnoreToast::LibSnoreToast) target_compile_definitions(SnoreToast PRIVATE UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX) # if there are changes to the callback mechanism we need to change the uuid for the activator SNORETOAST_CALLBACK_UUID target_compile_definitions(SnoreToast PRIVATE SNORETOAST_CALLBACK_UUID="{383803B6-AFDA-4220-BFC3-0DBF810106BF}" ) add_executable(SnoreToast::SnoreToast ALIAS SnoreToast) install(TARGETS SnoreToast SnoreToastActions EXPORT LibSnoreToastConfig RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(FILES snoretoastactions.h DESTINATION include/snoretoast) install(EXPORT LibSnoreToastConfig DESTINATION lib/cmake/libsnoretoast NAMESPACE SnoreToast::)