tidy-html5/CMakeLists.txt

207 lines
7.5 KiB
CMake
Raw Normal View History

# CMakeLists.txt - 20150130 - 20140801 - for github htacg/tidy-html5
2014-08-03 18:08:57 +00:00
cmake_minimum_required (VERSION 2.8)
project (tidy5)
2015-01-29 17:25:57 +00:00
# ### NOTE: *** Adjust version.txt when required ***
# read 'version' file into a variable (stripping any newlines or spaces)
file(READ version.txt versionFile)
if (NOT versionFile)
message(FATAL_ERROR "Unable to determine libtidy version. version.txt file is missing.")
endif()
string(STRIP "${versionFile}" LIBTIDY_VERSION)
2015-01-29 17:25:57 +00:00
string(REPLACE "." ";" VERSION_LIST ${LIBTIDY_VERSION})
list(GET VERSION_LIST 0 TIDY_MAJOR_VERSION)
list(GET VERSION_LIST 1 TIDY_MINOR_VERSION)
list(GET VERSION_LIST 2 TIDY_POINT_VERSION)
2014-08-03 18:08:57 +00:00
# Allow developer to select is Dynamic or static library built
set( LIB_TYPE STATIC ) # set default static
2015-01-28 16:15:44 +00:00
option( BUILD_SHARED_LIB "Set ON to build Shared (DLL) Library" OFF )
option( BUILD_TAB2SPACE "Set ON to build utility app, tab2space" OFF )
option( BUILD_SAMPLE_CODE "Set ON to build the sample code" OFF )
2014-08-03 18:08:57 +00:00
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "*** Have SIZEOF void * = 8, so 64-bit")
set( IS_64_BIT 1 )
else ()
message(STATUS "*** SIZEOF void * != 8, so not 64-bit")
endif ()
2014-08-03 18:08:57 +00:00
if(CMAKE_COMPILER_IS_GNUCXX)
set( WARNING_FLAGS -Wall )
endif(CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set( WARNING_FLAGS "-Wall -Wno-overloaded-virtual" )
endif()
if(WIN32 AND MSVC)
# turn off various warnings
set(WARNING_FLAGS "${WARNING_FLAGS} /wd4996")
# C4090: 'function' : different 'const' qualifiers
2014-08-06 10:09:13 +00:00
# C4244: '=' : conversion from '__int64' to 'uint', possible loss of data
# C4267: 'function' : conversion from 'size_t' to 'uint', possible loss of data
2014-08-03 18:08:57 +00:00
# foreach(warning 4244 4251 4267 4275 4290 4786 4305)
2014-08-06 10:09:13 +00:00
foreach(warning 4090 4244 4267)
2014-08-03 18:08:57 +00:00
set(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
endforeach()
set( MSVC_FLAGS "-DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS" )
if (IS_64_BIT)
set( MSVC_FLAGS "${MSVC_FLAGS} -DWIN64" )
endif ()
2014-08-03 18:08:57 +00:00
# if (${MSVC_VERSION} EQUAL 1600)
# set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
# endif (${MSVC_VERSION} EQUAL 1600)
2015-01-20 17:09:01 +00:00
# set( NOMINMAX 1 )
# to distinguish between debug and release lib in windows
set( CMAKE_DEBUG_POSTFIX "d" ) # little effect in unix
2014-08-03 18:08:57 +00:00
else()
2014-08-06 10:09:13 +00:00
# add any gcc flags
2014-08-03 18:08:57 +00:00
endif()
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT" )
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}" )
add_definitions ( -DHAVE_CONFIG_H )
add_definitions ( -DSUPPORT_UTF16_ENCODINGS=1 )
add_definitions ( -DSUPPORT_ASIAN_ENCODINGS=1 )
add_definitions ( -DSUPPORT_ACCESSIBILITY_CHECKS=1 )
2015-01-29 17:25:57 +00:00
add_definitions ( -DLIBTIDY_VERSION="${LIBTIDY_VERSION}" )
2014-08-03 18:08:57 +00:00
if(BUILD_SHARED_LIB)
set(LIB_TYPE SHARED)
2015-01-29 17:25:57 +00:00
message("*** Building DLL library ${LIB_TYPE}, version ${LIBTIDY_VERSION}")
2014-08-03 18:08:57 +00:00
else(BUILD_SHARED_LIB)
2015-01-29 17:25:57 +00:00
message("*** Building static library ${LIB_TYPE}, version ${LIBTIDY_VERSION}")
2014-08-03 18:08:57 +00:00
endif(BUILD_SHARED_LIB)
include_directories ( "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/src" )
##############################################################################
### tidy library
# file locations
set ( SRCDIR src )
set ( INCDIR include )
# file lists
set ( CFILES
${SRCDIR}/access.c ${SRCDIR}/attrs.c ${SRCDIR}/istack.c
${SRCDIR}/parser.c ${SRCDIR}/tags.c ${SRCDIR}/entities.c
${SRCDIR}/lexer.c ${SRCDIR}/pprint.c ${SRCDIR}/charsets.c ${SRCDIR}/clean.c
${SRCDIR}/localize.c ${SRCDIR}/config.c ${SRCDIR}/alloc.c
${SRCDIR}/attrask.c ${SRCDIR}/attrdict.c ${SRCDIR}/attrget.c
${SRCDIR}/buffio.c ${SRCDIR}/fileio.c ${SRCDIR}/streamio.c
${SRCDIR}/tagask.c ${SRCDIR}/tmbstr.c ${SRCDIR}/utf8.c
${SRCDIR}/tidylib.c ${SRCDIR}/mappedio.c ${SRCDIR}/gdoc.c )
set ( HFILES
${INCDIR}/platform.h ${INCDIR}/tidy.h ${INCDIR}/tidyenum.h
${INCDIR}/buffio.h )
set ( LIBHFILES
${SRCDIR}/access.h ${SRCDIR}/attrs.h ${SRCDIR}/attrdict.h ${SRCDIR}/charsets.h
${SRCDIR}/clean.h ${SRCDIR}/config.h ${SRCDIR}/entities.h
${SRCDIR}/fileio.h ${SRCDIR}/forward.h ${SRCDIR}/lexer.h
${SRCDIR}/mappedio.h ${SRCDIR}/message.h ${SRCDIR}/parser.h
${SRCDIR}/pprint.h ${SRCDIR}/streamio.h ${SRCDIR}/tags.h
${SRCDIR}/tmbstr.h ${SRCDIR}/utf8.h ${SRCDIR}/tidy-int.h
${SRCDIR}/version.h ${SRCDIR}/gdoc.h )
if (MSVC)
list(APPEND CFILES ${SRCDIR}/sprtf.c)
list(APPEND LIBHFILES ${SRCDIR}/sprtf.h)
endif ()
2015-01-24 12:14:12 +00:00
set(name lib-tidy)
2014-08-03 18:08:57 +00:00
add_library ( ${name} ${LIB_TYPE} ${CFILES} ${HFILES} ${LIBHFILES} )
set_target_properties( ${name} PROPERTIES
OUTPUT_NAME tidy5
)
set_target_properties( ${name} PROPERTIES
VERSION ${LIBTIDY_VERSION}
SOVERSION ${TIDY_MAJOR_VERSION} )
2015-01-28 16:15:44 +00:00
if (BUILD_SHARED_LIB)
set_target_properties( ${name} PROPERTIES
COMPILE_FLAGS "-DBUILD_SHARED_LIB"
)
set_target_properties( ${name} PROPERTIES
COMPILE_FLAGS "-DBUILDING_SHARED_LIB"
)
endif ()
2015-01-24 12:14:12 +00:00
list ( APPEND add_LIBS ${name} )
2014-08-06 10:09:13 +00:00
install(TARGETS ${name}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
2014-08-06 12:36:33 +00:00
install( FILES ${HFILES} DESTINATION include )
2014-08-03 18:08:57 +00:00
##########################################################
### main executable
set(name tidy5)
set ( BINDIR console )
add_executable( ${name} ${BINDIR}/tidy.c )
target_link_libraries( ${name} ${add_LIBS} )
if (MSVC)
set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
endif ()
2015-01-28 16:15:44 +00:00
if (BUILD_SHARED_LIB)
set_target_properties( ${name} PROPERTIES
COMPILE_FLAGS "-DBUILD_SHARED_LIB"
)
endif ()
2014-08-06 10:09:13 +00:00
install (TARGETS ${name} DESTINATION bin)
2014-08-03 18:08:57 +00:00
2015-01-28 16:15:44 +00:00
if (BUILD_TAB2SPACE)
set(name tab2space)
add_executable( ${name} ${BINDIR}/tab2space.c )
if (MSVC)
set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
endif ()
# no INSTALL of this 'local' tool
2014-08-03 18:08:57 +00:00
endif ()
if (BUILD_SAMPLE_CODE)
set(name test71)
set(dir console)
add_executable( ${name} ${dir}/${name}.cxx )
if (MSVC)
set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
endif ()
target_link_libraries( ${name} ${add_LIBS} )
# no INSTALL of this 'local' sample
endif ()
##########################################################
### Create deb and RPM
##########################################################
IF(WIN32)
2015-03-05 22:20:46 +00:00
set(CPACK_GENERATOR "ZIP;NSIS")
else(WIN32)
2015-03-05 22:20:46 +00:00
set(CPACK_GENERATOR "TGZ;DEB;RPM")
endif(WIN32)
set(CPACK_PACKAGE_VENDOR "HTML Tidy Advocacy Community Group")
set(CPACK_PACKAGE_CONTACT "maintainer@htacg.org")
set(CPACK_PACKAGE_VERSION ${LIBTIDY_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR "${TIDY_MAJOR_VERSION}")
set(CPACK_PACKAGE_VERSION_MINOR "${TIDY_MINOR_VERSION}")
set(CPACK_PACKAGE_VERSION_PATCH "${TIDY_POINT_VERSION}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.md")
## debian config
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://www.html-tidy.org/")
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc")
set(CPACK_DEBIAN_PACKAGE_SECTION "Libraries")
set(BITNESS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITNESS 64)
endif()
set( CPACK_PACKAGE_FILE_NAME "tidy5-${CPACK_PACKAGE_VERSION}-${BITNESS}bit" )
INCLUDE(CPack)
2014-08-03 18:08:57 +00:00
# eof
2015-01-24 12:14:12 +00:00