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 "2")
26 set(YAML_CPP_VERSION_PATCH "6")
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)
56 ### Sources, headers, directories and libs
58 file(GLOB sources "src/[a-zA-Z]*.cpp")
59 file(GLOB public_headers "include/yaml-cpp/[a-zA-Z]*.h")
60 file(GLOB private_headers "src/[a-zA-Z]*.h")
62 if(YAML_CPP_BUILD_CONTRIB)
63 file(GLOB contrib_sources "src/contrib/[a-zA-Z]*.cpp")
64 file(GLOB contrib_public_headers "include/yaml-cpp/contrib/[a-zA-Z]*.h")
65 file(GLOB contrib_private_headers "src/contrib/[a-zA-Z]*.h")
67 add_definitions(-DYAML_CPP_NO_CONTRIB)
71 message(STATUS "sources: ${sources}")
72 message(STATUS "public_headers: ${public_headers}")
73 message(STATUS "private_headers: ${private_headers}")
74 message(STATUS "contrib_sources: ${contrib_sources}")
75 message(STATUS "contrib_public_headers: ${contrib_public_headers}")
76 message(STATUS "contrib_private_headers: ${contrib_private_headers}")
79 include_directories(${YAML_CPP_SOURCE_DIR}/include)
83 ### General compilation settings
86 set(LABEL_SUFFIX "shared")
88 set(LABEL_SUFFIX "static")
92 if(APPLE_UNIVERSAL_BIN)
93 set(CMAKE_OSX_ARCHITECTURES ppc;i386)
98 set(CMAKE_OSX_SYSROOT "iphoneos4.2")
99 set(CMAKE_OSX_ARCHITECTURES "armv6;armv7")
103 if(BUILD_SHARED_LIBS)
104 add_definitions(-D${PROJECT_NAME}_DLL) # use or build Windows DLL
106 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
107 set(CMAKE_INSTALL_PREFIX "C:/")
112 if(CMAKE_COMPILER_IS_GNUCXX)
115 set(CMAKE_SHARED_LIBRARY_PREFIX "") # DLLs do not have a "lib" prefix
116 set(CMAKE_IMPORT_LIBRARY_PREFIX "") # same for DLL import libs
117 set(CMAKE_LINK_DEF_FILE_FLAG "") # CMake workaround (2.8.3)
121 if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
122 set(CMAKE_BUILD_TYPE Release)
125 set(CMAKE_CXX_FLAGS_RELEASE "-O2")
126 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
127 set(CMAKE_CXX_FLAGS_DEBUG "-g")
128 set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
130 set(GCC_EXTRA_OPTIONS "")
132 set(FLAG_TESTED "-Wextra")
133 check_cxx_compiler_flag(${FLAG_TESTED} FLAG_WEXTRA)
135 set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
138 set(CMAKE_CXX_FLAGS "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${CMAKE_CXX_FLAGS}")
140 add_custom_target(debuggable $(MAKE) clean
141 COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
142 COMMENT "Adjusting settings for debug compilation"
144 add_custom_target(releasable $(MAKE) clean
145 COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
146 COMMENT "Adjusting settings for release compilation"
150 # Microsoft VisualC++ specialities
153 # a) Change MSVC runtime library settings (/MD[d], /MT[d], /ML[d] (single-threaded until VS 2003))
154 # plus set lib suffix for later use and project label accordingly
155 # see http://msdn.microsoft.com/en-us/library/aa278396(v=VS.60).aspx
156 # http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.71).aspx
157 set(LIB_RT_SUFFIX "md") # CMake defaults to /MD for MSVC
158 set(LIB_RT_OPTION "/MD")
160 if(NOT MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML)
161 if(MSVC_STHREADED_RT) # User wants to have old single-threaded static runtime libraries
162 set(LIB_RT_SUFFIX "ml")
163 set(LIB_RT_OPTION "/ML")
164 if(NOT ${MSVC_VERSION} LESS 1400)
165 message(FATAL_ERROR "Single-threaded static runtime libraries (/ML) only available until VS .NET 2003 (7.1).")
168 set(LIB_RT_SUFFIX "mt")
169 set(LIB_RT_OPTION "/MT")
172 # correct linker options
173 foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
174 foreach(config_name "" DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
175 set(var_name "${flag_var}")
176 if(NOT "${config_name}" STREQUAL "")
177 set(var_name "${var_name}_${config_name}")
179 string(REPLACE "/MD" "${LIB_RT_OPTION}" ${var_name} "${${var_name}}")
184 set(LABEL_SUFFIX "${LABEL_SUFFIX} ${LIB_RT_SUFFIX}")
186 # b) Change prefix for static libraries
187 set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # to distinguish static libraries from DLL import libs
189 # c) Correct suffixes for static libraries
190 if(NOT BUILD_SHARED_LIBS)
192 set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}")
196 # /W3 = set warning level; see http://msdn.microsoft.com/en-us/library/thxezb7y.aspx
197 # /wd4127 = disable warning C4127 "conditional expression is constant"; see http://msdn.microsoft.com/en-us/library/6t66728h.aspx
198 # /wd4355 = disable warning C4355 "'this' : used in base member initializer list"; http://msdn.microsoft.com/en-us/library/3c594ae3.aspx
199 set(CMAKE_CXX_FLAGS "/W3 /wd4127 /wd4355 /D_SCL_SECURE_NO_WARNINGS ${CMAKE_CXX_FLAGS}")
204 ### General install settings
207 set(_library_dir bin) # .dll are in PATH, like executables
209 set(_library_dir lib)
212 set(INCLUDE_INSTALL_DIR include/yaml-cpp)
213 set(LIB_INSTALL_DIR "${_library_dir}${LIB_SUFFIX}")
215 set(_INSTALL_DESTINATIONS
216 RUNTIME DESTINATION bin
217 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
218 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
230 ${contrib_public_headers}
231 ${contrib_private_headers}
234 set_target_properties(yaml-cpp PROPERTIES
235 VERSION "${YAML_CPP_VERSION}"
236 SOVERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}"
237 PROJECT_LABEL "yaml-cpp ${LABEL_SUFFIX}"
241 set_target_properties(yaml-cpp PROPERTIES
242 XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "3.0"
247 if(NOT BUILD_SHARED_LIBS)
248 # correct library names
249 set_target_properties(yaml-cpp PROPERTIES
250 DEBUG_POSTFIX "${LIB_TARGET_SUFFIX}d"
251 RELEASE_POSTFIX "${LIB_TARGET_SUFFIX}"
252 MINSIZEREL_POSTFIX "${LIB_TARGET_SUFFIX}"
253 RELWITHDEBINFO_POSTFIX "${LIB_TARGET_SUFFIX}"
258 install(TARGETS yaml-cpp ${_INSTALL_DESTINATIONS})
262 ${contrib_public_headers}
263 DESTINATION ${INCLUDE_INSTALL_DIR}
267 set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
268 configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
269 install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
276 if(YAML_CPP_BUILD_TOOLS)
277 add_subdirectory(test)
278 add_subdirectory(util)