Permalink
Browse files

cmake build system: link with system yaml-cpp if available

Signed-off-by: Tim Blechmann <tim@klingt.org>
  • Loading branch information...
timblechmann committed Sep 30, 2012
1 parent 9b40b55 commit 001cbc078134d9747ec4711c5680947f09a10895
View
@@ -194,7 +194,8 @@ endif()
option(SC_SYMLINK_CLASSLIB "Place a symlink of SCCLassLibrary instead of copying" OFF)
option(SC_OX "Try to compile with support for C++0x (experimental, mainly related to supernova)" OFF)
-option(SYSTEM_BOOST "Use boost libraries from system" OFF)
+option(SYSTEM_BOOST "Use boost libraries from system" OFF)
+option(SYSTEM_YAMLCPP "Use yaml-cpp library from system" ON)
#############################################
# some default libraries
@@ -206,7 +207,7 @@ if (NOT PTHREADS_FOUND)
endif()
include_directories(${PTHREADS_INCLUDE_DIR})
-if (MSVC OR MINGW)
+if(MSVC OR MINGW)
set(MATH_LIBRARY "")
else()
find_library(MATH_LIBRARY m)
@@ -235,7 +236,11 @@ else()
message("building boost libraries manually")
endif()
-
+if(SYSTEM_YAMLCPP)
+ find_package(YamlCpp)
+else()
+ set(YAMLCPP_FOUND OFF)
+endif()
#############################################
# some preprocessor flags
@@ -287,6 +292,12 @@ endif()
#############################################
# subdirectories
add_subdirectory(external_libraries)
+
+if(NOT YAMLCPP_FOUND)
+ set(YAMLCPP_LIBRARY yaml)
+ set(YAMLCPP_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/external_libraries/yaml-cpp-0.3.0/include)
+endif()
+
add_subdirectory(server)
add_subdirectory(lang)
add_subdirectory(editors)
@@ -0,0 +1,50 @@
+# Locate yaml-cpp
+#
+# This module defines
+# YAMLCPP_FOUND, if false, do not try to link to yaml-cpp
+# YAMLCPP_LIBRARY, where to find yaml-cpp
+# YAMLCPP_INCLUDE_DIR, where to find yaml.h
+#
+# By default, the dynamic libraries of yaml-cpp will be found. To find the static ones instead,
+# you must set the YAMLCPP_STATIC_LIBRARY variable to TRUE before calling find_package(YamlCpp ...).
+#
+# If yaml-cpp is not installed in a standard path, you can use the YAMLCPP_DIR CMake variable
+# to tell CMake where yaml-cpp is.
+
+# attempt to find static library first if this is set
+if(YAMLCPP_STATIC_LIBRARY)
+ set(YAMLCPP_STATIC libyaml-cpp.a)
+endif()
+
+# find the yaml-cpp include directory
+find_path(YAMLCPP_INCLUDE_DIR yaml-cpp/yaml.h
+ PATH_SUFFIXES include
+ PATHS
+ ~/Library/Frameworks/yaml-cpp/include/
+ /Library/Frameworks/yaml-cpp/include/
+ /usr/local/include/
+ /usr/include/
+ /sw/yaml-cpp/ # Fink
+ /opt/local/yaml-cpp/ # DarwinPorts
+ /opt/csw/yaml-cpp/ # Blastwave
+ /opt/yaml-cpp/
+ ${YAMLCPP_DIR}/include/)
+
+# find the yaml-cpp library
+find_library(YAMLCPP_LIBRARY
+ NAMES ${YAMLCPP_STATIC} yaml-cpp
+ PATH_SUFFIXES lib64 lib
+ PATHS ~/Library/Frameworks
+ /Library/Frameworks
+ /usr/local
+ /usr
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ ${YAMLCPP_DIR}/lib)
+
+# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(YAMLCPP DEFAULT_MSG YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY)
+mark_as_advanced(YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY)
@@ -139,7 +139,7 @@ endif()
include_directories(${CMAKE_SOURCE_DIR}/include/common)
include_directories(${CMAKE_SOURCE_DIR}/include/plugin_interface)
-include_directories(${CMAKE_SOURCE_DIR}/external_libraries/yaml-cpp-0.3.0/include)
+include_directories(${YAMLCPP_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/external_libraries/boost)
# For QtCollider headers:
include_directories(${CMAKE_SOURCE_DIR})
@@ -166,7 +166,7 @@ else()
endif()
-target_link_libraries( ${ide_name} ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARY} yaml)
+target_link_libraries( ${ide_name} ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARY} ${YAMLCPP_LIBRARY})
if(APPLE)
target_link_libraries( ${ide_name} "-framework CoreServices")
@@ -66,9 +66,13 @@ if (SUPERNOVA)
endif()
endif()
-# yaml-cpp
-include_directories(${CMAKE_SOURCE_DIR}/external_libraries/yaml-cpp-0.3.0/include)
-aux_source_directory(${CMAKE_SOURCE_DIR}/external_libraries/yaml-cpp-0.3.0/src yaml_src)
-CREATE_FINAL_FILE(${CMAKE_CURRENT_BINARY_DIR}/libyamlcpp.cpp ${yaml_src})
+if(NOT YAMLCPP_FOUND)
+ message(STATUS "using bundled libyaml-cpp")
-add_library(yaml STATIC ${CMAKE_CURRENT_BINARY_DIR}/libyamlcpp.cpp)
+ # yaml-cpp
+ include_directories(${CMAKE_SOURCE_DIR}/external_libraries/yaml-cpp-0.3.0/include)
+ aux_source_directory(${CMAKE_SOURCE_DIR}/external_libraries/yaml-cpp-0.3.0/src yaml_src)
+ CREATE_FINAL_FILE(${CMAKE_CURRENT_BINARY_DIR}/libyamlcpp.cpp ${yaml_src})
+
+ add_library(yaml STATIC ${CMAKE_CURRENT_BINARY_DIR}/libyamlcpp.cpp)
+endif()
View
@@ -4,9 +4,10 @@ include_directories(${CMAKE_SOURCE_DIR}/include/common
${CMAKE_SOURCE_DIR}/include/server
${CMAKE_SOURCE_DIR}/common
+ ${YAMLCPP_INCLUDE_DIR}
+
${CMAKE_SOURCE_DIR}/external_libraries/boost-lockfree
${CMAKE_SOURCE_DIR}/external_libraries/threadpool
- ${CMAKE_SOURCE_DIR}/external_libraries/yaml-cpp-0.3.0/include
${CMAKE_SOURCE_DIR}/external_libraries/TLSF-2.4.6/src
LangSource/Bison)
@@ -277,7 +278,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(libsclang rt)
endif()
-target_link_libraries(libsclang ${PTHREADS_LIBRARY} yaml)
+target_link_libraries(libsclang ${PTHREADS_LIBRARY} ${YAMLCPP_LIBRARY})
if(SC_QT)
target_link_libraries(libsclang ${QT_COLLIDER_LIBS})
@@ -33,7 +33,8 @@ include_directories(
${CMAKE_SOURCE_DIR}/external_libraries/boost-lockfree
${CMAKE_SOURCE_DIR}/external_libraries/boost
${CMAKE_SOURCE_DIR}/external_libraries/threadpool
- ${CMAKE_SOURCE_DIR}/external_libraries/yaml-cpp-0.3.0/include
+ ${YAMLCPP_INCLUDE_DIR}
+
${CMAKE_SOURCE_DIR}/external_libraries/TLSF-2.4.6/src
)
@@ -232,7 +233,7 @@ if (Boost_FOUND)
else()
target_link_libraries(${scappbundlename} boost_thread)
endif()
-target_link_libraries(${scappbundlename} yaml)
+target_link_libraries(${scappbundlename} ${YAMLCPP_LIBRARY})
target_link_libraries(${scappbundlename} "-framework ApplicationServices")
target_link_libraries(${scappbundlename} "-framework Carbon")

0 comments on commit 001cbc0

Please sign in to comment.