OSDN Git Service

設定変更。
[wordring-tm/wordring-tm.git] / third-party / tidy-html5-master / CMakeLists.txt
1 # CMakeLists.txt - 20150402 - 20150130 - 20140801 - for github htacg/tidy-html5
2 # Prepare for changing the name to 'tidy'
3 cmake_minimum_required (VERSION 2.8.8)
4
5 set(LIB_NAME tidy5)
6
7 project (${LIB_NAME})
8
9 # ### NOTE: *** Adjust version.txt when required ***
10 # read 'version' file into a variable (stripping any newlines or spaces)
11 file(READ version.txt versionFile)
12 if (NOT versionFile)
13     message(FATAL_ERROR "Unable to determine libtidy version. version.txt file is missing.")
14 endif()
15 string(STRIP "${versionFile}" LIBTIDY_VERSION)
16 string(REPLACE "." ";" VERSION_LIST ${LIBTIDY_VERSION})
17 list(GET VERSION_LIST 0 TIDY_MAJOR_VERSION)
18 list(GET VERSION_LIST 1 TIDY_MINOR_VERSION)
19 list(GET VERSION_LIST 2 TIDY_POINT_VERSION)
20
21 # Allow developer to select is Dynamic or static library built
22 set( LIB_TYPE STATIC )  # set default static
23 option( BUILD_SHARED_LIB "Set ON to build Shared (DLL) Library"   OFF )
24 option( BUILD_TAB2SPACE  "Set ON to build utility app, tab2space" OFF )
25 option( BUILD_SAMPLE_CODE "Set ON to build the sample code"       OFF )
26
27 if(CMAKE_COMPILER_IS_GNUCXX)
28     set( WARNING_FLAGS -Wall )
29 endif(CMAKE_COMPILER_IS_GNUCXX)
30
31 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 
32    set( WARNING_FLAGS "-Wall -Wno-overloaded-virtual" )
33 endif() 
34
35 if(WIN32 AND MSVC)
36     # turn off various warnings
37     set(WARNING_FLAGS "${WARNING_FLAGS} /wd4996")
38     # C4090: 'function' : different 'const' qualifiers
39     # C4244: '=' : conversion from '__int64' to 'uint', possible loss of data
40     # C4267: 'function' : conversion from 'size_t' to 'uint', possible loss of data
41     # foreach(warning 4244 4251 4267 4275 4290 4786 4305)
42     foreach(warning 4090 4244 4267)
43         set(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
44     endforeach()
45     set( MSVC_FLAGS "-DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS" )
46     # if (${MSVC_VERSION} EQUAL 1600)
47     #    set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
48     # endif (${MSVC_VERSION} EQUAL 1600)
49     # set( NOMINMAX 1 )
50     # to distinguish between debug and release lib in windows
51     set( CMAKE_DEBUG_POSTFIX "d" ) # little effect in unix
52 else()
53     # add any gcc flags
54 endif()
55
56 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT" )
57 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT" )
58 set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}" )
59
60 add_definitions ( -DHAVE_CONFIG_H )
61 add_definitions ( -DSUPPORT_UTF16_ENCODINGS=1 )
62 add_definitions ( -DSUPPORT_ASIAN_ENCODINGS=1 )
63 add_definitions ( -DSUPPORT_ACCESSIBILITY_CHECKS=1 )
64 add_definitions ( -DLIBTIDY_VERSION="${LIBTIDY_VERSION}" )
65
66 # Issue #188 - Support user items in platform.h
67 if (TIDY_CONFIG_FILE)
68     add_definitions( -DTIDY_CONFIG_FILE="${TIDY_CONFIG_FILE}" )
69 endif ()
70 if (TIDY_USER_CONFIG_FILE)
71     add_definitions( -DTIDY_USER_CONFIG_FILE="${TIDY_USER_CONFIG_FILE}" )
72 endif ()
73 if (SUPPORT_GETPWNAM)
74     add_definitions( -DSUPPORT_GETPWNAM=1 )
75 endif ()
76
77 if(BUILD_SHARED_LIB)
78    set(LIB_TYPE SHARED)
79    message("*** Building DLL library ${LIB_TYPE}, version ${LIBTIDY_VERSION}")
80 else(BUILD_SHARED_LIB)
81    message("*** Building static library ${LIB_TYPE}, version ${LIBTIDY_VERSION}")
82 endif(BUILD_SHARED_LIB)
83
84 include_directories ( "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/src" )
85
86 ##############################################################################
87 ### tidy library
88 # file locations
89 set ( SRCDIR src )
90 set ( INCDIR include )
91 # file lists
92 set ( CFILES
93         ${SRCDIR}/access.c       ${SRCDIR}/attrs.c        ${SRCDIR}/istack.c
94         ${SRCDIR}/parser.c       ${SRCDIR}/tags.c         ${SRCDIR}/entities.c
95         ${SRCDIR}/lexer.c        ${SRCDIR}/pprint.c       ${SRCDIR}/charsets.c ${SRCDIR}/clean.c
96         ${SRCDIR}/localize.c     ${SRCDIR}/config.c       ${SRCDIR}/alloc.c
97         ${SRCDIR}/attrask.c      ${SRCDIR}/attrdict.c     ${SRCDIR}/attrget.c
98         ${SRCDIR}/buffio.c       ${SRCDIR}/fileio.c       ${SRCDIR}/streamio.c
99         ${SRCDIR}/tagask.c       ${SRCDIR}/tmbstr.c       ${SRCDIR}/utf8.c
100         ${SRCDIR}/tidylib.c      ${SRCDIR}/mappedio.c     ${SRCDIR}/gdoc.c )
101 set ( HFILES
102         ${INCDIR}/platform.h     ${INCDIR}/tidy.h         ${INCDIR}/tidyenum.h
103         ${INCDIR}/buffio.h )
104 set ( LIBHFILES
105         ${SRCDIR}/access.h       ${SRCDIR}/attrs.h        ${SRCDIR}/attrdict.h ${SRCDIR}/charsets.h
106         ${SRCDIR}/clean.h        ${SRCDIR}/config.h       ${SRCDIR}/entities.h
107         ${SRCDIR}/fileio.h       ${SRCDIR}/forward.h      ${SRCDIR}/lexer.h
108         ${SRCDIR}/mappedio.h     ${SRCDIR}/message.h      ${SRCDIR}/parser.h
109         ${SRCDIR}/pprint.h       ${SRCDIR}/streamio.h     ${SRCDIR}/tags.h
110         ${SRCDIR}/tmbstr.h       ${SRCDIR}/utf8.h         ${SRCDIR}/tidy-int.h
111         ${SRCDIR}/version.h      ${SRCDIR}/gdoc.h  )
112 if (MSVC)
113     list(APPEND CFILES ${SRCDIR}/sprtf.c)
114     list(APPEND LIBHFILES ${SRCDIR}/sprtf.h)
115 endif ()
116 set(name lib-tidy)
117 add_library ( ${name} ${LIB_TYPE} ${CFILES} ${HFILES} ${LIBHFILES} )
118 set_target_properties( ${name} PROPERTIES 
119     OUTPUT_NAME ${LIB_NAME}
120     )
121 set_target_properties( ${name} PROPERTIES
122                                VERSION   ${LIBTIDY_VERSION}
123                                SOVERSION ${TIDY_MAJOR_VERSION} )
124 if (BUILD_SHARED_LIB)
125 set_target_properties( ${name} PROPERTIES 
126     COMPILE_FLAGS "-DBUILD_SHARED_LIB"
127     )
128 set_target_properties( ${name} PROPERTIES 
129     COMPILE_FLAGS "-DBUILDING_SHARED_LIB"
130     )
131 endif ()                               
132 list ( APPEND add_LIBS ${name} )
133 install(TARGETS ${name}
134     RUNTIME DESTINATION bin
135     ARCHIVE DESTINATION lib
136     LIBRARY DESTINATION lib
137     )
138 install( FILES ${HFILES} DESTINATION include )
139
140 ##########################################################
141 ### main executable
142 set(name ${LIB_NAME})
143 set ( BINDIR console )
144 add_executable( ${name} ${BINDIR}/tidy.c )
145 target_link_libraries( ${name} ${add_LIBS} )
146 if (MSVC)
147     set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
148 endif ()
149 if (BUILD_SHARED_LIB)
150 set_target_properties( ${name} PROPERTIES 
151     COMPILE_FLAGS "-DBUILD_SHARED_LIB"
152     )
153 endif ()                               
154 install (TARGETS ${name} DESTINATION bin)
155
156 if (BUILD_TAB2SPACE)
157     set(name tab2space)
158     add_executable( ${name} ${BINDIR}/tab2space.c )
159     if (MSVC)
160         set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
161     endif ()
162     # no INSTALL of this 'local' tool
163 endif ()
164
165 if (BUILD_SAMPLE_CODE)
166     set(name test71)
167     set(dir console)
168     add_executable( ${name} ${dir}/${name}.cxx )
169     if (MSVC)
170         set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
171     endif ()
172     target_link_libraries( ${name} ${add_LIBS} )
173     # no INSTALL of this 'local' sample
174 endif ()
175
176 #==========================================================
177 # Create man pages
178 #==========================================================
179 if (UNIX)
180     find_program( XSLTPROC_FOUND xsltproc )
181     if (XSLTPROC_FOUND)
182         ## NOTE: man name must match exe ie currently `${LIB_NAME}.1` not `tidy.1`
183         ## also could use `manpath` command output to determine target install path
184         message(STATUS "*** Generating man ***")
185         set(TIDY_MANFILE ${LIB_NAME}.1)
186         set(TIDY1XSL ../documentation/tidy1.xsl)
187         set(TIDYHELP ${CMAKE_BINARY_DIR}/tidy-help.xml)
188         set(TIDYCONFIG ${CMAKE_BINARY_DIR}/tidy-config.xml)
189         add_custom_target(man ALL DEPENDS "${CMAKE_BINARY_DIR}/${LIB_NAME}")
190  
191         # run built EXE to generate xml output 
192         add_custom_command(
193             TARGET man
194             COMMAND ${CMAKE_BINARY_DIR}/${LIB_NAME} -xml-help > ${TIDYHELP}
195             COMMENT "Generate ${TIDYHELP}"
196             VERBATIM
197         )
198
199         # run built EXE to generate more xml output 
200         add_custom_command(
201             TARGET man
202             COMMAND ${CMAKE_BINARY_DIR}/${LIB_NAME} -xml-config > ${TIDYCONFIG}
203             COMMENT "Generate ${TIDYCONFIG}"
204             VERBATIM
205         )
206
207         # run xsltproc to generate the install files..
208         add_custom_command(
209             TARGET man
210             DEPENDS ${TIDYHELP}
211             COMMAND xsltproc ARGS ${TIDY1XSL} ${TIDYHELP} > ${CMAKE_BINARY_DIR}/${TIDY_MANFILE}
212             COMMENT "Generate ${TIDY_MANFILE}"
213             VERBATIM
214         )
215
216         install(FILES ${CMAKE_BINARY_DIR}/${TIDY_MANFILE} DESTINATION share/man/man1)
217     endif ()
218 endif ()
219
220
221 ##########################################################
222 ### Create MSI,EXE, DMG, DEB/RPM
223 ### TODO: Check each of these builds
224 ##########################################################
225 set(BITNESS 32)
226 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
227   set(BITNESS 64)
228 endif()
229 if (WIN32)
230     # MSI - this needs WiX Tooset installed and a path to candle.exe
231     # EXE - this needs NSIS tools to be in path
232     set(CPACK_GENERATOR "NSIS;WIX;ZIP")
233     set(CPACK_SOURCE_GENERATOR "ZIP")
234     set(CPACK_WIX_UPGRADE_GUID "D809598A-B513-4752-B268-0BAC403B00E4")
235 elseif ( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
236     set(CPACK_GENERATOR "PackageMake")
237     set(CPACK_SOURCE_GENERATOR "TGZ")
238 else ()
239     set(CPACK_GENERATOR "DEB;RPM")
240     set(CPACK_SOURCE_GENERATOR "TGZ")
241 endif ()
242
243 set(CPACK_PACKAGE_NAME "${LIB_NAME}")
244 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${LIB_NAME} - HTML syntax checker")
245 set(CPACK_PACKAGE_VENDOR "HTML Tidy Advocacy Community Group")
246 set(CPACK_PACKAGE_CONTACT "maintainer@htacg.org")
247
248 set(CPACK_PACKAGE_VERSION ${LIBTIDY_VERSION})
249 set(CPACK_PACKAGE_VERSION_MAJOR "${TIDY_MAJOR_VERSION}")
250 set(CPACK_PACKAGE_VERSION_MINOR "${TIDY_MINOR_VERSION}")
251 set(CPACK_PACKAGE_VERSION_PATCH "${TIDY_POINT_VERSION}")
252 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.html")
253
254 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
255 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.html")
256 set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README.html")
257
258 ## debian config
259 set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
260 set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://www.html-tidy.org/")
261 #set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc")
262 set(CPACK_DEBIAN_PACKAGE_SECTION "Libraries")
263
264 set(CPACK_SOURCE_IGNORE_FILES "${CMAKE_SOURCE_DIR}/test/;${CMAKE_SOURCE_DIR}/build/;${CMAKE_SOURCE_DIR}/.git/")
265
266 if (NOT WIN32 AND NOT APPLE)
267 set( CPACK_PACKAGE_FILE_NAME "${LIB_NAME}-${CPACK_PACKAGE_VERSION}-${BITNESS}bit" )
268 endif ()
269
270 include(CPack)
271
272 # eof