2 # TinyGetText build script
3 # Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 # Create a directory build/ and change to it. Run
29 # This creates a set of Makefiles to build the project. Run
35 CMAKE_POLICY(SET CMP0005 NEW)
37 ## Project name to use as command prefix
42 ### CMake configuration
44 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
45 IF(COMMAND cmake_policy)
46 CMAKE_POLICY(SET CMP0003 NEW)
47 ENDIF(COMMAND cmake_policy)
48 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${tinygettext_SOURCE_DIR})
50 # move some config clutter to the advanced section
52 CMAKE_BACKWARDS_COMPATIBILITY
55 EXECUTABLE_OUTPUT_PATH
56 CMAKE_OSX_ARCHITECTURES
60 ## Reveal library type choice to users
61 OPTION(BUILD_SHARED_LIBS "Produce dynamic library instead of static archive" ON)
63 ## Add iconv to include directories
65 FIND_PACKAGE(ICONV REQUIRED)
66 INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
70 INCLUDE(CheckCXXSourceCompiles)
72 SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${ICONV_INCLUDE_DIR})
73 CHECK_CXX_SOURCE_COMPILES(
76 // this declaration will fail when there already exists a non const char** version which returns size_t
77 double iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
78 int main() { return 0; }
83 # TODO: better way of config
86 ADD_DEFINITIONS(-DHAVE_ICONV_CONST)
87 ELSE(HAVE_ICONV_CONST)
88 REMOVE_DEFINITIONS(-DHAVE_ICONV_CONST)
89 ENDIF(HAVE_ICONV_CONST)
91 ## TinyGetText library compilation
93 ## build list of source files
95 FILE(GLOB TINYGETTEXT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.cpp)
96 FILE(GLOB TINYGETTEXT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/tinygettext/*.hpp)
98 ## define a target for building the library
100 ADD_LIBRARY(tinygettext ${TINYGETTEXT_SOURCES})
102 ## Add tinygettext dir to search path
104 INCLUDE_DIRECTORIES(include/)
108 OPTION(WERROR "Stops on first compiler warning in debug mode" OFF)
109 IF(CMAKE_COMPILER_IS_GNUCC)
110 ADD_DEFINITIONS(-std=c++0x -O3 -Wall -Wextra -Weffc++ -pedantic)
111 # -ansi fails in MinGW
112 OPTION(WARNINGS "Enable long list of warnings for compiler to check" ON)
115 -Wabi -Wctor-dtor-privacy
116 -Wstrict-null-sentinel
119 -Wsign-promo -Wswitch-enum
120 -Wcast-align -Wcast-qual
121 -Wdisabled-optimization
125 -Winvalid-pch -Wunsafe-loop-optimizations
127 -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn
131 -Wsign-conversion -Wstack-protector
133 -Wswitch-default -Wswitch-enum
136 # -Wconversion (find alternative to using toupper(int) on char)
137 # -Wpadded (DictionaryManager has a bool that sticks out)
140 ADD_DEFINITIONS(-Werror)
142 ENDIF(CMAKE_COMPILER_IS_GNUCC)
146 ADD_DEFINITIONS(-DVERSION=${VERSION})
148 ## Generate test executables in the right place
150 SET(EXECUTABLE_OUTPUT_PATH ${tinygettext_BINARY_DIR}/test)
152 ## Build tinygettext tests
154 FOREACH(TEST tinygettext_test po_parser_test)
155 ## Add target for tinygettext test
156 ADD_EXECUTABLE(${TEST} test/${TEST}.cpp)
157 ## Link with tinygettext library
158 TARGET_LINK_LIBRARIES(${TEST} tinygettext)
159 TARGET_LINK_LIBRARIES(${TEST} ${ICONV_LIBRARY})
162 ## Install tinygettext
164 # use standardized variable name
165 SET(LIB_SUBDIR "lib${LIB_SUFFIX}"
166 CACHE STRING "Subdirectory of prefix into which libraries are installed (e.g., lib32, lib64)")
168 ## prepare tinygettext.pc
169 CONFIGURE_FILE(tinygettext.pc.in tinygettext.pc @ONLY)
171 INSTALL(TARGETS tinygettext
172 ARCHIVE DESTINATION ${LIB_SUBDIR}
173 LIBRARY DESTINATION ${LIB_SUBDIR})
174 INSTALL(FILES ${TINYGETTEXT_HEADERS}
175 DESTINATION include/tinygettext)
176 INSTALL(FILES ${tinygettext_BINARY_DIR}/tinygettext.pc
177 DESTINATION ${LIB_SUBDIR}/pkgconfig)