4 ## Due to Mac OSX we need to keep compatibility with CMake 2.6
5 # see http://www.cmake.org/Wiki/CMake_Policies
6 cmake_minimum_required(VERSION 2.6)
7 # see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0012
9 cmake_policy(SET CMP0012 OLD)
11 # see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015
13 cmake_policy(SET CMP0015 OLD)
16 include(CheckCXXCompilerFlag)
24 set(YAML_CPP_VERSION_MAJOR "0")
25 set(YAML_CPP_VERSION_MINOR "3")
26 set(YAML_CPP_VERSION_PATCH "0")
27 set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}")
36 option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" ON)
37 option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON)
41 # see http://www.cmake.org/cmake/help/cmake2.6docs.html#variable:BUILD_SHARED_LIBS
42 # http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library
43 option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
46 option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)
48 # --> Microsoft Visual C++
49 # see http://msdn.microsoft.com/en-us/library/aa278396(v=VS.60).aspx
50 # http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.71).aspx
51 option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON)
52 option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF)
55 ### Sources, headers, directories and libs
57 set(header_directory "include/yaml-cpp/")
59 file(GLOB sources "src/[a-zA-Z]*.cpp")
60 file(GLOB public_headers "include/yaml-cpp/[a-zA-Z]*.h")
61 file(GLOB private_headers "src/[a-zA-Z]*.h")
63 if(YAML_CPP_BUILD_CONTRIB)
64 file(GLOB contrib_sources "src/contrib/[a-zA-Z]*.cpp")
65 file(GLOB contrib_public_headers "include/yaml-cpp/contrib/[a-zA-Z]*.h")
66 file(GLOB contrib_private_headers "src/contrib/[a-zA-Z]*.h")
68 add_definitions(-DYAML_CPP_NO_CONTRIB)
72 message(STATUS "sources: ${sources}")
73 message(STATUS "public_headers: ${public_headers}")
74 message(STATUS "private_headers: ${private_headers}")
75 message(STATUS "contrib_sources: ${contrib_sources}")
76 message(STATUS "contrib_public_headers: ${contrib_public_headers}")
77 message(STATUS "contrib_private_headers: ${contrib_private_headers}")
80 include_directories(${YAML_CPP_SOURCE_DIR}/include)
81 include_directories(${YAML_CPP_SOURCE_DIR}/src)
85 ### General compilation settings
88 set(LABEL_SUFFIX "shared")
90 set(LABEL_SUFFIX "static")
94 if(APPLE_UNIVERSAL_BIN)
95 set(CMAKE_OSX_ARCHITECTURES ppc;i386)
100 set(CMAKE_OSX_SYSROOT "iphoneos4.2")
101 set(CMAKE_OSX_ARCHITECTURES "armv6;armv7")
105 if(BUILD_SHARED_LIBS)
106 add_definitions(-D${PROJECT_NAME}_DLL) # use or build Windows DLL
108 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
109 set(CMAKE_INSTALL_PREFIX "C:/")
114 if(CMAKE_COMPILER_IS_GNUCXX)
117 set(CMAKE_SHARED_LIBRARY_PREFIX "") # DLLs do not have a "lib" prefix
118 set(CMAKE_IMPORT_LIBRARY_PREFIX "") # same for DLL import libs
119 set(CMAKE_LINK_DEF_FILE_FLAG "") # CMake workaround (2.8.3)
123 if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
124 set(CMAKE_BUILD_TYPE Release)
127 set(CMAKE_CXX_FLAGS_RELEASE "-O2")
128 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
129 set(CMAKE_CXX_FLAGS_DEBUG "-g")
130 set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
132 set(GCC_EXTRA_OPTIONS "")
134 set(FLAG_TESTED "-Wextra")
135 check_cxx_compiler_flag(${FLAG_TESTED} FLAG_WEXTRA)
137 set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
140 set(CMAKE_CXX_FLAGS "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${CMAKE_CXX_FLAGS}")
142 add_custom_target(debuggable $(MAKE) clean
143 COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
144 COMMENT "Adjusting settings for debug compilation"
146 add_custom_target(releasable $(MAKE) clean
147 COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
148 COMMENT "Adjusting settings for release compilation"
152 # Microsoft VisualC++ specialities
155 # a) Change MSVC runtime library settings (/MD[d], /MT[d], /ML[d] (single-threaded until VS 2003))
156 # plus set lib suffix for later use and project label accordingly
157 # see http://msdn.microsoft.com/en-us/library/aa278396(v=VS.60).aspx
158 # http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.71).aspx
159 set(LIB_RT_SUFFIX "md") # CMake defaults to /MD for MSVC
160 set(LIB_RT_OPTION "/MD")
162 if(NOT MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML)
163 if(MSVC_STHREADED_RT) # User wants to have old single-threaded static runtime libraries
164 set(LIB_RT_SUFFIX "ml")
165 set(LIB_RT_OPTION "/ML")
166 if(NOT ${MSVC_VERSION} LESS 1400)
167 message(FATAL_ERROR "Single-threaded static runtime libraries (/ML) only available until VS .NET 2003 (7.1).")
170 set(LIB_RT_SUFFIX "mt")
171 set(LIB_RT_OPTION "/MT")
174 # correct linker options
175 foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
176 foreach(config_name "" DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
177 set(var_name "${flag_var}")
178 if(NOT "${config_name}" STREQUAL "")
179 set(var_name "${var_name}_${config_name}")
181 string(REPLACE "/MD" "${LIB_RT_OPTION}" ${var_name} "${${var_name}}")
186 set(LABEL_SUFFIX "${LABEL_SUFFIX} ${LIB_RT_SUFFIX}")
188 # b) Change prefix for static libraries
189 set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # to distinguish static libraries from DLL import libs
191 # c) Correct suffixes for static libraries
192 if(NOT BUILD_SHARED_LIBS)
194 set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}")
198 # /W3 = set warning level; see http://msdn.microsoft.com/en-us/library/thxezb7y.aspx
199 # /wd4127 = disable warning C4127 "conditional expression is constant"; see http://msdn.microsoft.com/en-us/library/6t66728h.aspx
200 # /wd4355 = disable warning C4355 "'this' : used in base member initializer list"; http://msdn.microsoft.com/en-us/library/3c594ae3.aspx
201 set(CMAKE_CXX_FLAGS "/W3 /wd4127 /wd4355 /D_SCL_SECURE_NO_WARNINGS ${CMAKE_CXX_FLAGS}")
206 ### General install settings
209 set(_library_dir bin) # .dll are in PATH, like executables
211 set(_library_dir lib)
214 set(INCLUDE_INSTALL_ROOT_DIR include)
216 set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_ROOT_DIR}/yaml-cpp)
217 set(LIB_INSTALL_DIR "${_library_dir}${LIB_SUFFIX}")
219 set(_INSTALL_DESTINATIONS
220 RUNTIME DESTINATION bin
221 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
222 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
234 ${contrib_public_headers}
235 ${contrib_private_headers}
238 set_target_properties(yaml-cpp PROPERTIES
239 VERSION "${YAML_CPP_VERSION}"
240 SOVERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}"
241 PROJECT_LABEL "yaml-cpp ${LABEL_SUFFIX}"
245 set_target_properties(yaml-cpp PROPERTIES
246 XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "3.0"
251 if(NOT BUILD_SHARED_LIBS)
252 # correct library names
253 set_target_properties(yaml-cpp PROPERTIES
254 DEBUG_POSTFIX "${LIB_TARGET_SUFFIX}d"
255 RELEASE_POSTFIX "${LIB_TARGET_SUFFIX}"
256 MINSIZEREL_POSTFIX "${LIB_TARGET_SUFFIX}"
257 RELWITHDEBINFO_POSTFIX "${LIB_TARGET_SUFFIX}"
262 install(TARGETS yaml-cpp ${_INSTALL_DESTINATIONS})
264 DIRECTORY ${header_directory}
265 DESTINATION ${INCLUDE_INSTALL_DIR}
266 FILES_MATCHING PATTERN "*.h"
270 set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
271 configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
272 install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
279 if(YAML_CPP_BUILD_TOOLS)
280 add_subdirectory(test)
281 add_subdirectory(util)