Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / external_libraries / yaml-cpp-0.3.0 / CMakeLists.txt
blob823ce201f1359f063734ef078c47a3402e29eec4
1 ###
2 ### CMake settings
3 ###
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
8 if(POLICY CMP0012)
9         cmake_policy(SET CMP0012 OLD)
10 endif()
11 # see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015
12 if(POLICY CMP0015)
13         cmake_policy(SET CMP0015 OLD)
14 endif()
16 include(CheckCXXCompilerFlag)
19 ###
20 ### Project settings
21 ###
22 project(YAML_CPP)
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}")
29 enable_testing()
32 ###
33 ### Project options
34 ###
35 ## Project stuff
36 option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" ON)
37 option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON)
39 ## Build options
40 # --> General
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)
45 # --> Apple
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)
54 ###
55 ### Sources, headers, directories and libs
56 ###
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")
67 else()
68         add_definitions(-DYAML_CPP_NO_CONTRIB)
69 endif()
71 if(VERBOSE)
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}")
78 endif()
80 include_directories(${YAML_CPP_SOURCE_DIR}/include)
81 include_directories(${YAML_CPP_SOURCE_DIR}/src)
84 ###
85 ### General compilation settings
86 ###
87 if(BUILD_SHARED_LIBS)
88         set(LABEL_SUFFIX "shared")
89 else()
90         set(LABEL_SUFFIX "static")
91 endif()
93 if(APPLE)
94         if(APPLE_UNIVERSAL_BIN)
95                 set(CMAKE_OSX_ARCHITECTURES ppc;i386)
96         endif()
97 endif()
99 if(IPHONE)
100         set(CMAKE_OSX_SYSROOT "iphoneos4.2")
101         set(CMAKE_OSX_ARCHITECTURES "armv6;armv7")
102 endif()
104 if(WIN32)
105         if(BUILD_SHARED_LIBS)
106                 add_definitions(-D${PROJECT_NAME}_DLL)  # use or build Windows DLL
107         endif()
108         if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
109                 set(CMAKE_INSTALL_PREFIX "C:/")
110         endif()
111 endif()
113 # GCC specialities
114 if(CMAKE_COMPILER_IS_GNUCXX)
115         ### General stuff
116         if(WIN32)
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)
120         endif()
122         ### Project stuff
123         if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
124                 set(CMAKE_BUILD_TYPE Release)
125         endif()
126         #
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")
131         #
132         set(GCC_EXTRA_OPTIONS "")
133         #
134         set(FLAG_TESTED "-Wextra")
135         check_cxx_compiler_flag(${FLAG_TESTED} FLAG_WEXTRA)
136         if(FLAG_WEXTRA)
137                 set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
138         endif()
139         #
140         set(CMAKE_CXX_FLAGS "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${CMAKE_CXX_FLAGS}")
141         #
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"
145                 VERBATIM)
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"
149                 VERBATIM)
150 endif()
152 # Microsoft VisualC++ specialities
153 if(MSVC)
154         ### General stuff
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")
161         #
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).")
168                         endif()
169                 else()
170                         set(LIB_RT_SUFFIX "mt")
171                         set(LIB_RT_OPTION "/MT")
172                 endif()
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}")
180                                 endif()
181                                 string(REPLACE "/MD" "${LIB_RT_OPTION}" ${var_name} "${${var_name}}")
182                         endforeach()
183                 endforeach()
184         endif()
185         #
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)
193                 ### General stuff
194                 set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}")
195         endif()
197         ### Project stuff
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}")
202 endif()
206 ### General install settings
208 if(WIN32)
209         set(_library_dir bin)   # .dll are in PATH, like executables
210 else()
211         set(_library_dir lib)
212 endif()
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}"
227 ### Library
229 add_library(yaml-cpp
230         ${sources}
231         ${public_headers}
232         ${private_headers}
233         ${contrib_sources}
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}"
244 if(IPHONE)
245         set_target_properties(yaml-cpp PROPERTIES
246                 XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "3.0"
247         )
248 endif()
250 if(MSVC)
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}"
258                 )
259         endif()
260 endif()
262 install(TARGETS yaml-cpp ${_INSTALL_DESTINATIONS})
263 install(
264         DIRECTORY ${header_directory}
265         DESTINATION ${INCLUDE_INSTALL_DIR}
266         FILES_MATCHING PATTERN "*.h"
269 if(UNIX)
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)
273 endif()
277 ### Extras
279 if(YAML_CPP_BUILD_TOOLS)
280         add_subdirectory(test)
281         add_subdirectory(util)
282 endif()