summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 002f5b853136811a65299bf0ed79fb358eb59080 (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
cmake_minimum_required(VERSION 2.8.8)

project(Ledger)

set(Ledger_VERSION_MAJOR 3)
set(Ledger_VERSION_MINOR 0)
set(Ledger_VERSION_PATCH 0)
set(Ledger_VERSION_DATE  20120518)

enable_testing()

########################################################################

option(USE_PYTHON "Build support for the Python scripting bridge" OFF)
option(USE_DOXYGEN "Build reference documentation using Doxygen" OFF)

option(NO_ASSERTS "Build without any internal consistency checks" OFF)
option(BUILD_DEBUG "Build support for runtime debugging" ON)

option(BUILD_LIBRARY "Build and install Ledger as a library" ON)
option(BUILD_DOCS "Build and install documentation" OFF)
option(BUILD_EMACSLISP "Build and install ledger-mode for Emacs" OFF)

if(BUILD_DEBUG)
  set(CMAKE_BUILD_TYPE Debug)
  set(DEBUG_MODE 1)
elseif(NO_ASSERTS)
  set(CMAKE_BUILD_TYPE Release)
  set(NDEBUG 1)
else()
  set(CMAKE_BUILD_TYPE Release)
endif()

########################################################################

find_package(PythonInterp)      # Used for running tests

if(USE_PYTHON)
  find_package(PythonLibs)
  if(PYTHONLIBS_FOUND)
    set(BOOST_PYTHON python)
    set(HAVE_BOOST_PYTHON 1)
    include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS})
  else()
    set(HAVE_BOOST_PYTHON 0)
    message("Could not find a Python library to use with Boost.Python")
  endif()
endif()

set(Boost_USE_MULTITHREADED OFF)

find_package(Boost 1.47.0
  REQUIRED date_time filesystem system iostreams regex 
           unit_test_framework test_exec_monitor
  OPTIONAL_COMPONENTS ${BOOST_PYTHON})

include_directories(SYSTEM ${Boost_INCLUDE_DIRS})

find_package(Gettext)           # Used for running tests

if(GETTEXT_FOUND)
  set(HAVE_GETTEXT 1)
else()
  set(HAVE_GETTEXT 0)
endif()

########################################################################

include(CheckIncludeFiles)

check_include_files(langinfo.h HAVE_LANGINFO_H)

include(CheckLibraryExists)

check_library_exists(edit readline "" HAVE_EDIT)

include(CheckFunctionExists)

check_function_exists(access HAVE_ACCESS)
check_function_exists(realpath HAVE_REALPATH)
check_function_exists(getpwuid HAVE_GETPWUID)
check_function_exists(getpwnam HAVE_GETPWNAM)
check_function_exists(isatty HAVE_ISATTY)

include(CheckCSourceCompiles)

check_c_source_compiles("
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main() {
  int status, pfd[2];
  status = pipe(pfd);
  status = fork();
  if (status < 0) {
    ;
  } else if (status == 0) {
    char *arg0 = NULL;

    status = dup2(pfd[0], STDIN_FILENO);

    close(pfd[1]);
    close(pfd[0]);

    execlp(\"\", arg0, (char *)0);
    perror(\"execl\");
    exit(1);
  } else {
    close(pfd[0]);
  }
  return 0;
}" UNIX_PIPES_COMPILES)

if(UNIX_PIPES_COMPILES)
  set(HAVE_UNIX_PIPES 1)
else()
  set(HAVE_UNIX_PIPES 0)
endif()

include(CheckCXXSourceRuns)
include(CMakePushCheckState)

cmake_push_check_state()

set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH} ${Boost_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${Boost_LIBRARIES} icuuc)

check_cxx_source_runs("
#include <boost/regex/icu.hpp>

using namespace boost;

int main() {
  std::string text = \"Активы\";
  u32regex r = make_u32regex(\"активы\", regex::perl | regex::icase);
  return u32regex_search(text, r) ? 0 : 1;
}" BOOST_REGEX_UNICODE_RUNS)

if(BOOST_REGEX_UNICODE_RUNS)
  set(HAVE_BOOST_REGEX_UNICODE 1)
else()
  set(HAVE_BOOST_REGEX_UNICODE 0)
endif()

cmake_pop_check_state()

cmake_push_check_state()

set(CMAKE_REQUIRED_FLAGS -std=c++11)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})

check_cxx_source_runs("
#include <regex>
#include <vector>
#include <iostream>

int main() {
  std::vector<int> x {0, 1, 2, 3, 4};
  for (auto i : x)
    std::cout << i << std::endl;

  std::regex r(\"foo\");
  std::cout << std::regex_match(\"foobar\", r) << std::endl;
  return 0;
}" CXX11_RUNS)

cmake_pop_check_state()

if(CXX11_RUNS)
  set(HAVE_CXX11 1)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
  set(HAVE_CXX11 0)
endif()

########################################################################

include_directories(${CMAKE_INCLUDE_PATH})

find_path(GMP_PATH gmp.h)
find_library(GMP_LIB gmp)
include_directories(SYSTEM "${GMP_PATH}")

find_path(MPFR_PATH mpfr.h)
find_library(MPFR_LIB mpfr)
include_directories(SYSTEM "${MPFR_PATH}")

find_path(EDIT_PATH histedit.h)
find_library(EDIT_LIB edit)
include_directories(SYSTEM "${EDIT_PATH}")

find_path(INTL_PATH libintl.h)
find_library(INTL_LIB intl)
include_directories(SYSTEM "${INTL_PATH}")

########################################################################

macro(add_ledger_library_dependencies _target)
  if(BUILD_LIBRARY)
    target_link_libraries(${_target} libledger)
  endif()
  target_link_libraries(${_target} ${MPFR_LIB})
  target_link_libraries(${_target} ${GMP_LIB})
  if(HAVE_EDIT)
    target_link_libraries(${_target} ${EDIT_LIB})
  endif()
  if(HAVE_GETTEXT)
    target_link_libraries(${_target} ${INTL_LIB})
  endif()
  if(HAVE_BOOST_PYTHON)
    target_link_libraries(${_target} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
  else()
    target_link_libraries(${_target} ${Boost_LIBRARIES})
  endif()
  if(HAVE_BOOST_REGEX_UNICODE)
    target_link_libraries(${_target} icuuc)
  endif()
endmacro(add_ledger_library_dependencies _target)

########################################################################

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})

# add the binary tree to the search path for include files so that we will
# find TutorialConfig.h
include_directories("${PROJECT_SOURCE_DIR}/lib")
include_directories("${PROJECT_SOURCE_DIR}/lib/utfcpp/source")
include_directories("${PROJECT_BINARY_DIR}")

configure_file(
  ${PROJECT_SOURCE_DIR}/src/system.hh.in
  ${PROJECT_BINARY_DIR}/system.hh)

add_subdirectory(src)
if(BUILD_DOCS)
  add_subdirectory(doc)
endif()
if(BUILD_EMACSLISP)
  add_subdirectory(lisp)
endif()
add_subdirectory(test)

########################################################################

# build a CPack driven installer package
include (InstallRequiredSystemLibraries)

set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/LICENSE.rtf")
set (CPACK_PACKAGE_VERSION_MAJOR "${Ledger_VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${Ledger_VERSION_MINOR}")
set (CPACK_PACKAGE_VERSION_PATCH "${Ledger_VERSION_PATCH}")

include (CPack)

### CMakeLists.txt ends here