Integrate support for MinGW Win32 builds.

* Add Win32Depends.cmake, which retrieves all dependencies from
  the Internet. Other ways of building the application on Win32
  are not supported.
* Install the application correctly on Win32.
* Make FindGTK2.cmake search for GIO.
* Make the project a C-only project, so g++ is not needed.
* Remove obsolete checks for strtok().
* Set WIN32_EXECUTABLE on the application.
This commit is contained in:
Přemysl Eric Janouch 2011-01-22 13:13:05 +01:00
parent a7cc4ef2a1
commit 2f5f87119d
4 changed files with 175 additions and 29 deletions

View File

@ -1,4 +1,4 @@
project (logdiag)
project (logdiag C)
cmake_minimum_required (VERSION 2.6.2)
# Default to 2.6.3 behaviour
@ -13,7 +13,6 @@ else (OPTION_NOINSTALL)
set (OPTION_NOINSTALL 0)
endif (OPTION_NOINSTALL)
# Version
set (project_VERSION_MAJOR "0")
set (project_VERSION_MINOR "0")
@ -26,9 +25,6 @@ set (project_VERSION "${project_VERSION}.${project_VERSION_PATCH}")
# For custom modules
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Gather package information
find_package (GTK2 2.12 REQUIRED gtk)
# Test this machine
include (CheckCSourceCompiles)
@ -43,17 +39,22 @@ CHECK_C_SOURCE_COMPILES (
int main (void) {return 0;}"
HAVE_RESTRICT)
include (CheckFunctionExists)
CHECK_FUNCTION_EXISTS ("strtok_r" HAVE_STRTOK_R)
CHECK_FUNCTION_EXISTS ("strtok_s" HAVE_STRTOK_S)
# Automatic retrieval of dependencies
if (WIN32)
set (HAVE_THREADSAFE_STRTOK true)
set (WIN32_DEPENDS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/win32-depends)
list (APPEND CMAKE_PREFIX_PATH ${WIN32_DEPENDS_PATH})
list (APPEND CMAKE_INCLUDE_PATH ${WIN32_DEPENDS_PATH}/lib)
list (APPEND CMAKE_C_FLAGS "-mms-bitfields")
add_custom_target (win32-depends COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/Win32Depends.cmake
WORKING_DIRECTORY ${WIN32_DEPENDS_PATH})
add_custom_target (win32-depends-clean COMMAND ${CMAKE_COMMAND} -E
remove_directory ${WIN32_DEPENDS_PATH})
endif (WIN32)
# Dependencies
find_package (GTK2 2.12 REQUIRED gtk)
find_package (Lua51 REQUIRED)
find_package (JsonGlib REQUIRED)
@ -167,7 +168,7 @@ add_library (liblogdiag STATIC ${liblogdiag_SOURCES} ${liblogdiag_HEADERS})
set_target_properties (liblogdiag PROPERTIES OUTPUT_NAME logdiag)
# Build the executable
add_executable (logdiag ${logdiag_SOURCES} ${logdiag_HEADERS})
add_executable (logdiag WIN32 ${logdiag_SOURCES} ${logdiag_HEADERS})
target_link_libraries (logdiag liblogdiag ${GTK2_LIBRARIES}
${JSON_GLIB_LIBRARIES} ${LUA_LIBRARIES})
@ -180,17 +181,35 @@ if (GTK_DOC_FOUND)
endif (GTK_DOC_FOUND)
# Installation
install (TARGETS logdiag DESTINATION bin)
install (DIRECTORY share/gui share/library
DESTINATION share/${CMAKE_PROJECT_NAME})
if (NOT WIN32)
if (WIN32)
install (TARGETS logdiag DESTINATION .)
install (DIRECTORY
${WIN32_DEPENDS_PATH}/bin/
DESTINATION .
FILES_MATCHING PATTERN "*.dll")
install (DIRECTORY
${WIN32_DEPENDS_PATH}/etc/
DESTINATION etc)
install (DIRECTORY
${WIN32_DEPENDS_PATH}/lib/glib-2.0
${WIN32_DEPENDS_PATH}/lib/gtk-2.0
${WIN32_DEPENDS_PATH}/lib/gdk-pixbuf-2.0
DESTINATION lib)
install (DIRECTORY
${WIN32_DEPENDS_PATH}/share/locale
${WIN32_DEPENDS_PATH}/share/themes
DESTINATION share)
else (WIN32)
install (TARGETS logdiag DESTINATION bin)
install (FILES share/logdiag.desktop DESTINATION share/applications)
install (DIRECTORY share/icons DESTINATION share)
install (DIRECTORY "${project_DOC_DIR}/html/"
DESTINATION share/gtk-doc/${CMAKE_PROJECT_NAME})
install (FILES LICENSE DESTINATION share/doc/${CMAKE_PROJECT_NAME})
endif (NOT WIN32)
endif (WIN32)
# CPack
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Schematic editor")
@ -206,7 +225,7 @@ set (CPACK_PACKAGE_FILE_NAME
set (CPACK_PACKAGE_INSTALL_DIRECTORY
"${PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
set (CPACK_SOURCE_IGNORE_FILES "/build;/.svn;/.git")
set (CPACK_SOURCE_IGNORE_FILES "/build;/.svn;/.git;/win32-depends")
set (CPACK_SOURCE_PACKAGE_FILE_NAME
"${PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")

137
Win32Depends.cmake Normal file
View File

@ -0,0 +1,137 @@
# Usage: cmake -P Win32Depends.cmake
# Directories
set (working_dir ${CMAKE_CURRENT_BINARY_DIR}/win32-depends)
set (pkg_dir ${working_dir}/packages)
set (bsdtar_dir ${working_dir}/bsdtar)
set (bsdtar_executable ${bsdtar_dir}/bsdtar)
set (tmp_dir ${working_dir}/tmp)
file (MAKE_DIRECTORY ${working_dir})
file (MAKE_DIRECTORY ${pkg_dir})
# Cleanup
message (STATUS "Cleaning up...")
file (GLOB files ${working_dir}/*)
list (REMOVE_ITEM files ${pkg_dir})
if (files)
file (REMOVE_RECURSE ${files})
endif (files)
# Packages
set (pkg_list "bsdtar" "gtk" "opensuse" "mingw_lua")
set (pkg_bsdtar_root "http://sourceforge.net/projects/mingw/files/MinGW")
set (pkg_bsdtar_urls
"${pkg_bsdtar_root}/libarchive/libarchive-2.8.3-1/bsdtar-2.8.3-1-mingw32-bin.tar.bz2"
"${pkg_bsdtar_root}/libarchive/libarchive-2.8.3-1/libarchive-2.8.3-1-mingw32-dll-2.tar.bz2"
"${pkg_bsdtar_root}/expat/expat-2.0.1-1/libexpat-2.0.1-1-mingw32-dll-1.tar.gz"
"${pkg_bsdtar_root}/xz/xz-4.999.9beta_20100401-1/liblzma-4.999.9beta_20100401-1-mingw32-dll-1.tar.bz2"
"${pkg_bsdtar_root}/bzip2/release%201.0.5-2/libbz2-1.0.5-2-mingw32-dll-2.tar.gz"
"${pkg_bsdtar_root}/zlib/zlib-1.2.3-1-mingw32/libz-1.2.3-1-mingw32-dll-1.tar.gz")
set (pkg_gtk_root "http://ftp.gnome.org/pub/gnome/binaries/win32")
set (pkg_gtk_urls
"${pkg_gtk_root}/gtk+/2.22/gtk+-bundle_2.22.1-20101227_win32.zip"
"${pkg_gtk_root}/librsvg/2.32/librsvg_2.32.1-1_win32.zip"
"${pkg_gtk_root}/librsvg/2.32/librsvg-dev_2.32.1-1_win32.zip"
"${pkg_gtk_root}/librsvg/2.32/svg-gdk-pixbuf-loader_2.32.1-1_win32.zip"
"${pkg_gtk_root}/libcroco/0.6/libcroco_0.6.2-1_win32.zip"
"${pkg_gtk_root}/dependencies/libxml2_2.7.7-1_win32.zip"
"${pkg_gtk_root}/dependencies/libxml2-dev_2.7.7-1_win32.zip")
set (pkg_opensuse_root "http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Factory/noarch")
set (pkg_opensuse_urls
"${pkg_opensuse_root}/mingw32-libjson-glib-0.12.0-2.36.noarch.rpm"
"${pkg_opensuse_root}/mingw32-json-glib-devel-0.12.0-2.36.noarch.rpm")
set (pkg_opensuse_strip "usr/i686-pc-mingw32/sys-root/mingw")
set (pkg_mingw_lua_root "http://sourceforge.net/projects/mingw-cross/files/%5BLIB%5D%20Lua")
set (pkg_mingw_lua_name "mingw32-lua-5.1.4-2")
set (pkg_mingw_lua_urls
"${pkg_mingw_lua_root}/${pkg_mingw_lua_name}/${pkg_mingw_lua_name}.zip")
set (pkg_mingw_lua_strip ${pkg_mingw_lua_name})
# Stage 1: fetch missing packages
foreach (pkg_set ${pkg_list})
foreach (url ${pkg_${pkg_set}_urls})
get_filename_component (filename ${url} NAME)
set (filename ${pkg_dir}/${filename})
if (NOT EXISTS ${filename})
message (STATUS "Downloading ${url}...")
file (DOWNLOAD ${url} ${filename} STATUS status)
list (GET status 0 status_errno)
list (GET status 1 status_msg)
if (status_errno)
file (REMOVE ${filename})
message (FATAL_ERROR "Download failed: ${status_msg}")
endif (status_errno)
endif (NOT EXISTS ${filename})
endforeach (url)
endforeach (pkg_set)
if (NOT WIN32)
message (FATAL_ERROR "Must run on Windows to extract packages; aborting")
endif (NOT WIN32)
# Stage 2: setup bsdtar first (RPM support)
file (MAKE_DIRECTORY ${tmp_dir})
foreach (url ${pkg_bsdtar_urls})
get_filename_component (filename ${url} NAME)
message (STATUS "Extracting ${filename}...")
set (filename ${pkg_dir}/${filename})
execute_process (COMMAND ${CMAKE_COMMAND} -E tar xf ${filename}
WORKING_DIRECTORY ${tmp_dir}
RESULT_VARIABLE status)
if (status)
message (FATAL_ERROR "Extraction failed: ${status}")
endif (status)
endforeach (url)
file (COPY ${tmp_dir}/bin/ DESTINATION ${bsdtar_dir})
file (REMOVE_RECURSE ${tmp_dir})
list (REMOVE_ITEM pkg_list "bsdtar")
# Stage 3: extract the rest of packages
foreach (pkg_set ${pkg_list})
foreach (url ${pkg_${pkg_set}_urls})
get_filename_component (filename ${url} NAME)
message (STATUS "Extracting ${filename}...")
set (filename ${pkg_dir}/${filename})
if (pkg_${pkg_set}_strip)
file (MAKE_DIRECTORY ${tmp_dir})
execute_process (COMMAND ${bsdtar_executable} -xf ${filename}
WORKING_DIRECTORY ${tmp_dir}
RESULT_VARIABLE status)
file (COPY ${tmp_dir}/${pkg_${pkg_set}_strip}/
DESTINATION ${working_dir})
file (REMOVE_RECURSE ${tmp_dir})
else (pkg_${pkg_set}_strip)
execute_process (COMMAND ${bsdtar_executable} -xf ${filename}
WORKING_DIRECTORY ${working_dir}
RESULT_VARIABLE status)
endif (pkg_${pkg_set}_strip)
if (status)
message (FATAL_ERROR "Extraction failed: ${status}")
endif (status)
endforeach (url)
endforeach (pkg_set)
# Stage 4: final touches
file (WRITE ${working_dir}/etc/gtk-2.0/gtkrc
"gtk-theme-name = \"MS-Windows\"")
set (gdk_pixbuf_libdir ${working_dir}/lib/gdk-pixbuf-2.0/2.10.0)
set (ENV{GDK_PIXBUF_MODULE_FILE} ${gdk_pixbuf_libdir}/loaders.cache)
set (ENV{GDK_PIXBUF_MODULEDIR} ${gdk_pixbuf_libdir}/loaders)
execute_process (COMMAND
${working_dir}/bin/gdk-pixbuf-query-loaders --update-cache
RESULT_VARIABLE result)
if (result)
message (FATAL_ERROR "gdk-pixbuf-query-loaders failed")
endif (result)

View File

@ -420,6 +420,7 @@ foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
_GTK2_FIND_INCLUDE_DIR(GTK2_GLIB_INCLUDE_DIR glib.h)
_GTK2_FIND_INCLUDE_DIR(GTK2_GLIBCONFIG_INCLUDE_DIR glibconfig.h)
_GTK2_FIND_LIBRARY (GTK2_GLIB_LIBRARY glib false true)
_GTK2_FIND_LIBRARY (GTK2_GIO_LIBRARY gio false true)
_GTK2_FIND_INCLUDE_DIR(GTK2_GOBJECT_INCLUDE_DIR gobject/gobject.h)
_GTK2_FIND_LIBRARY (GTK2_GOBJECT_LIBRARY gobject false true)
@ -529,6 +530,7 @@ foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
GTK2_GLIB_INCLUDE_DIR
GTK2_GLIBCONFIG_INCLUDE_DIR
GTK2_GLIB_LIBRARY
GTK2_GIO_LIBRARY
GTK2_GDK_INCLUDE_DIR
GTK2_GDKCONFIG_INCLUDE_DIR

View File

@ -22,10 +22,6 @@
#cmakedefine HAVE_SANE___RESTRICT
#cmakedefine HAVE_RESTRICT
#cmakedefine HAVE_STRTOK_R
#cmakedefine HAVE_STRTOK_S
#cmakedefine HAVE_THREADSAFE_STRTOK
#cmakedefine HAVE_GETTEXT
@ -52,13 +48,5 @@
#endif
#endif /* ! HAVE_SANE___RESTRICT */
#ifndef HAVE_STRTOK_R
#ifdef HAVE_STRTOK_S
#define strtok_r strtok_s
#elif defined(HAVE_THREADSAFE_STRTOK)
#define strtok_r(a, b, c) strtok(a, b)
#endif
#endif /* ! HAVE_STRTOK_R */
#endif /* __CONFIG_H__ */