cmake: supernova - missing include_directories() for Jack
[supercollider.git] / external_libraries / yaml-cpp-0.2.6 / CMakeLists.txt
blob9665ebd17144bdf12d8eefbfddcfe643d4d3e9e0
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 "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}")
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)
55 ###
56 ### Sources, headers, directories and libs
57 ###
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")
66 else()
67         add_definitions(-DYAML_CPP_NO_CONTRIB)
68 endif()
70 if(VERBOSE)
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}")
77 endif()
79 include_directories(${YAML_CPP_SOURCE_DIR}/include)
82 ###
83 ### General compilation settings
84 ###
85 if(BUILD_SHARED_LIBS)
86         set(LABEL_SUFFIX "shared")
87 else()
88         set(LABEL_SUFFIX "static")
89 endif()
91 if(APPLE)
92         if(APPLE_UNIVERSAL_BIN)
93                 set(CMAKE_OSX_ARCHITECTURES ppc;i386)
94         endif()
95 endif()
97 if(IPHONE)
98         set(CMAKE_OSX_SYSROOT "iphoneos4.2")
99         set(CMAKE_OSX_ARCHITECTURES "armv6;armv7")
100 endif()
102 if(WIN32)
103         if(BUILD_SHARED_LIBS)
104                 add_definitions(-D${PROJECT_NAME}_DLL)  # use or build Windows DLL
105         endif()
106         if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
107                 set(CMAKE_INSTALL_PREFIX "C:/")
108         endif()
109 endif()
111 # GCC specialities
112 if(CMAKE_COMPILER_IS_GNUCXX)
113         ### General stuff
114         if(WIN32)
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)
118         endif()
120         ### Project stuff
121         if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
122                 set(CMAKE_BUILD_TYPE Release)
123         endif()
124         #
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")
129         #
130         set(GCC_EXTRA_OPTIONS "")
131         #
132         set(FLAG_TESTED "-Wextra")
133         check_cxx_compiler_flag(${FLAG_TESTED} FLAG_WEXTRA)
134         if(FLAG_WEXTRA)
135                 set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
136         endif()
137         #
138         set(CMAKE_CXX_FLAGS "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${CMAKE_CXX_FLAGS}")
139         #
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"
143                 VERBATIM)
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"
147                 VERBATIM)
148 endif()
150 # Microsoft VisualC++ specialities
151 if(MSVC)
152         ### General stuff
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")
159         #
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).")
166                         endif()
167                 else()
168                         set(LIB_RT_SUFFIX "mt")
169                         set(LIB_RT_OPTION "/MT")
170                 endif()
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}")
178                                 endif()
179                                 string(REPLACE "/MD" "${LIB_RT_OPTION}" ${var_name} "${${var_name}}")
180                         endforeach()
181                 endforeach()
182         endif()
183         #
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)
191                 ### General stuff
192                 set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}")
193         endif()
195         ### Project stuff
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}")
200 endif()
204 ### General install settings
206 if(WIN32)
207         set(_library_dir bin)   # .dll are in PATH, like executables
208 else()
209         set(_library_dir lib)
210 endif()
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}"
223 ### Library
225 add_library(yaml-cpp
226         ${sources}
227         ${public_headers}
228         ${private_headers}
229         ${contrib_sources}
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}"
240 if(IPHONE)
241         set_target_properties(yaml-cpp PROPERTIES
242                 XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "3.0"
243         )
244 endif()
246 if(MSVC)
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}"
254                 )
255         endif()
256 endif()
258 install(TARGETS yaml-cpp ${_INSTALL_DESTINATIONS})
259 install(
260         FILES
261                 ${public_headers}
262                 ${contrib_public_headers}
263         DESTINATION ${INCLUDE_INSTALL_DIR}
266 if(UNIX)
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)
270 endif()
274 ### Extras
276 if(YAML_CPP_BUILD_TOOLS)
277         add_subdirectory(test)
278         add_subdirectory(util)
279 endif()