diff --git a/CMake/mitkFunctionCompileSnippets.cmake b/CMake/mitkFunctionCompileSnippets.cmake index e65d3036d9..c0ea9dae33 100644 --- a/CMake/mitkFunctionCompileSnippets.cmake +++ b/CMake/mitkFunctionCompileSnippets.cmake @@ -1,38 +1,40 @@ function(mitkFunctionCompileSnippets snippet_path) # get all files called "main.cpp" file(GLOB_RECURSE main_cpp_list "${snippet_path}/main.cpp") foreach(main_cpp_file ${main_cpp_list}) # get the directory containing the main.cpp file get_filename_component(main_cpp_dir "${main_cpp_file}" PATH) set(snippet_src_files ) # If there exists a "files.cmake" file in the snippet directory, # include it and assume it sets the variable "snippet_src_files" # to a list of source files for the snippet. if(EXISTS "${main_cpp_dir}/files.cmake") include("${main_cpp_dir}/files.cmake") else() # glob all files in the directory and add them to the snippet src list file(GLOB_RECURSE snippet_src_files "${main_cpp_dir}/*") endif() # Uset the top-level directory name as the executable name string(REPLACE "/" ";" main_cpp_dir_tokens "${main_cpp_dir}") list(GET main_cpp_dir_tokens -1 snippet_exec_name) - set(snippet_target_name "Snippet/${snippet_exec_name}") + set(snippet_target_name "Snippet-${snippet_exec_name}") add_executable(${snippet_target_name} ${snippet_src_files}) if(ARGN) target_link_libraries(${snippet_target_name} ${ARGN}) endif() set_target_properties(${snippet_target_name} PROPERTIES LABELS Documentation RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/snippets" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/snippets" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/snippets" OUTPUT_NAME ${snippet_exec_name} ) endforeach() endfunction() diff --git a/Core/Code/Service/mitkModuleUtils.cpp b/Core/Code/Service/mitkModuleUtils.cpp index 4cd893e881..68d52d3868 100644 --- a/Core/Code/Service/mitkModuleUtils.cpp +++ b/Core/Code/Service/mitkModuleUtils.cpp @@ -1,154 +1,156 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkModuleUtils.h" +#include namespace mitk { #ifdef __GNUC__ #define _GNU_SOURCE #include std::string GetLibraryPath_impl(const std::string& /*libName*/, const void* symbol) { Dl_info info; if (dladdr(symbol, &info)) { return info.dli_fname; } return ""; } void* GetSymbol_impl(const std::string& libName, const char* symbol) { void* selfHandle = dlopen(libName.c_str(), RTLD_LAZY); if (selfHandle) { void* addr = dlsym(selfHandle, symbol); dlclose(selfHandle); return addr; } return 0; } #elif _WIN32 +#include #include void PrintLastError_impl(const std::string& context) { // Retrieve the system error message for the last-error code LPVOID lpMsgBuf; LPVOID lpDisplayBuf; DWORD dw = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); // Display the error message and exit the process lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)context.c_str()) + 50) * sizeof(TCHAR)); StringCchPrintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR), TEXT("Error in context %s (%d): %s"), context.c_str(), dw, lpMsgBuf); std::string errMsg((LPCTSTR)lpDisplayBuf); LocalFree(lpMsgBuf); LocalFree(lpDisplayBuf); MITK_DEBUG(true) << errMsg; } std::string GetLibraryPath_impl(const std::string& libName, const void *symbol) { HMODULE handle = 0; if (libName.empty()) { // get the handle for the executable handle = GetModuleHandle(0); } else { handle = GetModuleHandle(libName.c_str()); } if (!handle) { PrintLastError_impl("GetLibraryPath_impl():GetModuleHandle()"); return ""; } char modulePath[512]; if (GetModuleFileName(handle, modulePath, 512)) { return modulePath; } PrintLastError_impl("GetLibraryPath_impl():GetModuleFileName()"); return ""; } void* GetSymbol_impl(const std::string& libName, const char* symbol) { HMODULE handle = GetModuleHandle(libName.c_str()); if (!handle) { PrintLastError_impl("GetSymbol_impl():GetModuleHandle()"); return 0; } void* addr = (void*)GetProcAddress(handle, symbol); if (!addr) { PrintLastError_impl(std::string("GetSymbol_impl():GetProcAddress(handle,") + std::string(symbol) + ")"); } return addr; } #else std::string GetLibraryPath_impl(const std::string& libName, const void* symbol) { return ""; } void* GetSymbol_impl(const std::string& libName, const char* symbol) { return 0; } #endif std::string ModuleUtils::GetLibraryPath(const std::string& libName, const void* symbol) { return GetLibraryPath_impl(libName, symbol); } void* ModuleUtils::GetSymbol(const std::string& libName, const char* symbol) { return GetSymbol_impl(libName, symbol); } }