forked from puppetlabs/facter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
147 lines (122 loc) · 5.46 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
cmake_minimum_required(VERSION 2.8.12)
project(FACTER)
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "Defaulting to a release build.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
option(YAMLCPP_STATIC "Use yaml-cpp's static libraries" OFF)
set(FACTER_PATH "" CACHE PATH "Specify the location to look for specific binaries before trying PATH.")
if (FACTER_PATH)
# Specify a preferred location for binary lookup that will be prioritized over PATH.
file(TO_CMAKE_PATH ${FACTER_PATH} FACTER_PATH_FIXED)
add_definitions(-DFACTER_PATH="${FACTER_PATH_FIXED}")
message(STATUS "Prioritizing binary lookup in ${FACTER_PATH_FIXED}")
endif()
set(FACTER_RUBY "" CACHE FILEPATH "Specify the location of libruby at compile-time, bypassing dynamic lookup.")
if (FACTER_RUBY)
file(TO_CMAKE_PATH ${FACTER_RUBY} FACTER_RUBY_PATH)
add_definitions(-DFACTER_RUBY="${FACTER_RUBY_PATH}")
message(STATUS "Fixing lookup for libruby to ${FACTERPATH_PATH}")
endif()
enable_testing()
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/vendor/leatherman/cmake")
include(cotire)
if (MINGW)
# MinGW crashes with large pre-compiled headers; ours definitely exceeds the limit.
# See http://stackoverflow.com/questions/10841306/cc1plus-exe-crash-when-using-large-precompiled-header-file
set(PRECOMPILED_HEADERS FALSE)
else()
set(PRECOMPILED_HEADERS TRUE)
endif()
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
# Allow searching in boxen installed homebrew directories
# http://stackoverflow.com/questions/1487752/how-do-i-instruct-cmake-to-look-for-libraries-installed-by-macports
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/boxen/homebrew/lib)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/boxen/homebrew/include)
endif()
# Before we find any packages, we want to pull in the common leatherman options, as they can affect commonly-used packages.
include(options)
# We use system, filesystem, regex, and log directly. Log depends on system, filesystem, datetime, and thread.
# For Windows, we've added locale to correctly generate a UTF-8 compatible default locale.
set(BOOST_PKGS program_options system filesystem date_time thread regex log)
if (WIN32)
list(APPEND BOOST_PKGS locale)
endif()
find_package(Boost 1.54 REQUIRED COMPONENTS ${BOOST_PKGS})
find_package(Ruby 1.9)
find_package(YAMLCPP REQUIRED)
if (NOT WITHOUT_OPENSSL)
find_package(OPENSSL)
endif()
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" AND NOT WITHOUT_BLKID)
find_package(BLKID)
endif()
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" AND NOT WITHOUT_CURL)
find_package(CURL)
if (CURL_FOUND)
add_definitions(-DUSE_CURL)
endif()
set_package_properties(CURL PROPERTIES DESCRIPTION "A free and easy-to-use client-side URL transfer library" URL "http://curl.haxx.se/libcurl/")
set_package_properties(CURL PROPERTIES TYPE OPTIONAL PURPOSE "Enables facts that require HTTP.")
endif()
# Display a summary of the features
include(FeatureSummary)
feature_summary(WHAT ALL)
if ("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")
find_library(SOCKET_LIBRARY socket)
if (SOCKET_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${SOCKET_LIBRARY})
link_libraries(socket)
endif()
find_library(KSTAT_LIBRARY kstat)
if (KSTAT_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${KSTAT_LIBRARY})
link_libraries(kstat)
endif()
endif()
# Set RPATH if not installing to a system library directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" INSTALL_IS_SYSTEM_DIR)
if ("${INSTALL_IS_SYSTEM_DIR}" STREQUAL "-1")
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif()
# Pull in common cflags setting from leatherman
include(cflags)
set(FACTER_CXX_FLAGS "${LEATHERMAN_CXX_FLAGS}")
# Force all binaries to be created in the same location.
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
if (WIN32)
# On Windows, DLL paths aren't hardcoded in the executable. We place all the executables and libraries
# in the same directory to avoid having to setup the DLL search path in the dev environment.
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
endif()
add_definitions(${LEATHERMAN_DEFINITIONS})
# Include vendor libraries
set(RAPIDJSON_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/vendor/rapidjson-0.11/include")
if (WIN32)
# We disabled installing Boost.Nowide; add back the library we use.
# CMake doesn't allow install targets in a different directory, so get the file.
install(FILES ${CMAKE_BINARY_DIR}/bin/libnowide.dll DESTINATION bin)
endif()
# Build against our leatherman tooling
set(LEATHERMAN_USE_LOCALE TRUE)
set(LEATHERMAN_USE_CATCH TRUE)
set(LEATHERMAN_USE_NOWIDE TRUE)
set(LEATHERMAN_USE_LOGGING TRUE)
add_subdirectory("vendor/leatherman")
#
# Add cpplint and cppcheck targets
#
file(GLOB_RECURSE ALL_SOURCES lib/src/*.cc lib/inc/*.hpp lib/inc/version.h exe/*.cc exe/*.hpp exe/*.h)
add_cpplint_files(${ALL_SOURCES})
enable_cpplint()
add_cppcheck_dirs("${PROJECT_SOURCE_DIR}/lib" "${PROJECT_SOURCE_DIR}/exe")
enable_cppcheck()
# Pull in helper macros for working with leatherman libraries
include(leatherman)
add_subdirectory(lib)
add_subdirectory(exe)
# Add test executables for unit testing
add_test(NAME "library\\ tests" COMMAND libfacter_test)
add_test(NAME "facter\\ smoke" COMMAND facter)