forked from tmhoward/h2sl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
178 lines (158 loc) · 5.97 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
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
cmake_minimum_required(VERSION 2.8)
project(h2sl)
OPTION(BUILD_SHARED_LIBS "build dynamic libraries" OFF)
set(H2SL_VERSION 1.0)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++0x)
if(APPLE)
add_definitions(-Wall -Wno-unused-const-variable -g -O3 -Wno-overloaded-virtual)
elseif(UNIX)
add_definitions(-Wall -Wno-unused-but-set-variable -g -O3)
endif()
# add the include directories to the build
set(DIRS src/common
src/symbol
src/language
src/parser
src/llm
src/dcg
src/util)
include_directories(${DIRS} ${CMAKE_INSTALL_PREFIX}/include ${CMAKE_BINARY_DIR}/include)
# search for the getgetopt program, exit if not found
find_program(GENGETOPT gengetopt)
if( NOT GENGETOPT )
message( FATAL_ERROR "gengetopt not found\n" )
return()
endif()
# function to generate the getgetopt source and header from a .ggo file
function(generate_ggo)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
cmake_parse_arguments(GENERATE_GGO "" "INPUT;OUTPUT" "" ${ARGN})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GENERATE_GGO_OUTPUT}.c ${CMAKE_CURRENT_BINARY_DIR}/${GENERATE_GGO_OUTPUT}.h
COMMAND ${GENGETOPT} -i ${CMAKE_CURRENT_SOURCE_DIR}/${GENERATE_GGO_INPUT} --file-name ${GENERATE_GGO_OUTPUT} --output-dir=${CMAKE_CURRENT_BINARY_DIR} --unamed-opts
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${GENERATE_GGO_INPUT}
)
endfunction(generate_ggo)
# search for the libxml2 package, exit if not found
find_package(LibXml2)
if( NOT LIBXML2_FOUND )
message( FATAL_ERROR "libxml2 not found\n" )
return()
endif()
include_directories(${LIBXML2_INCLUDE_DIR})
# search for the boost package, exit if not found
find_package(Boost 1.45.0 COMPONENTS system thread filesystem)
if( NOT Boost_FOUND )
message( FATAL_ERROR "Boost not found\n" )
return()
endif()
include_directories(${Boost_INCLUDE_DIR})
# search for the LBFGS libraries
find_library(LBFGS_LIBRARY NAMES liblbfgs lbfgs HINTS ${CMAKE_BINARY_DIR}/lib /usr/lib /usr/local/lib /opt/local/lib)
if( NOT LBFGS_LIBRARY )
message( FATAL_ERROR "lbfgs not found\n")
return()
endif()
# search for the QT package, exit if not found
find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
if( NOT Qt4_FOUND )
message( FATAL_ERROR "Qt4 not found\n" )
return()
endif()
include(${QT_USE_FILE})
include_directories(${QT_INCLUDE_DIR})
# function for installing headers
function(process_hdrs)
cmake_parse_arguments(PROCESS_HDRS "" "" "HDRS;QT_HDRS" ${ARGN})
foreach(msg_hdr ${MSG_HDRS})
set(msg_hdr_fullpath "${CMAKE_BINARY_DIR}/${msg_hdr}")
set(MSG_HDRS_FULLPATH ${MSG_HDRS_FULLPATH} ${msg_hdr_fullpath})
endforeach(msg_hdr)
install(FILES
${HDRS}
${QT_HDRS}
${MSG_HDRS_FULLPATH}
DESTINATION include/h2sl)
endfunction(process_hdrs)
# function for compiling and installing a library
function(process_lib)
cmake_parse_arguments(PROCESS_LIB "" "LIB" "SRCS;QT_HDRS;DEPS" ${ARGN})
if( QT_HDRS )
qt_wrap_cpp(${LIB} MOC_SRCS ${QT_HDRS})
endif( QT_HDRS )
if(BUILD_SHARED_LIBS)
add_library(${PROCESS_LIB_LIB} SHARED
${PROCESS_LIB_SRCS}
${MOC_SRCS}
${MSG_HDRS})
target_link_libraries(${PROCESS_LIB_LIB} ${PROCESS_LIB_DEPS})
install(TARGETS ${PROCESS_LIB_LIB}
LIBRARY
DESTINATION lib
ARCHIVE
DESTINATION lib)
else(BUILD_SHARED_LIBS)
set(PROCESS_LIB_LIB_STATIC "${PROCESS_LIB_LIB}")
add_library(${PROCESS_LIB_LIB_STATIC} STATIC
${PROCESS_LIB_SRCS}
${MOC_SRCS}
${MSG_HDRS})
set_target_properties(${PROCESS_LIB_LIB_STATIC} PROPERTIES OUTPUT_NAME ${PROCESS_LIB_LIB})
install(TARGETS ${PROCESS_LIB_LIB_STATIC}
LIBRARY
DESTINATION lib
ARCHIVE
DESTINATION lib)
endif()
endfunction(process_lib)
# function for compiling and installing the binaries for the h2sl project
function(process_bin_srcs)
cmake_parse_arguments(PROCESS_BIN_SRCS "" "LIB" "BIN_SRCS;GGOS;DEPS" ${ARGN})
foreach(ggo ${PROCESS_BIN_SRCS_GGOS})
string(REGEX REPLACE ".ggo" "_cmdline" tmp ${ggo})
generate_ggo(INPUT ${ggo} OUTPUT ${tmp})
endforeach(ggo)
foreach(bin_src ${PROCESS_BIN_SRCS_BIN_SRCS})
set(bin_src_cmdline "${CMAKE_CURRENT_BINARY_DIR}/${bin_src}")
string(REGEX REPLACE ".cc" "_cmdline.c" bin_src_cmdline ${bin_src_cmdline})
set(bin "h2sl-${bin_src}")
string(REGEX REPLACE ".cc" "" bin ${bin})
string(REGEX REPLACE "_" "-" bin ${bin})
add_executable(${bin} ${bin_src} ${bin_src_cmdline})
target_link_libraries(${bin} ${PROCESS_BIN_SRCS_LIB} ${PROCESS_BIN_SRCS_DEPS})
set(BINS ${BINS} ${bin})
endforeach(bin_src)
install(TARGETS
${BINS}
DESTINATION bin)
endfunction(process_bin_srcs)
# function to build the documentation for the h2sl project
if(BUILD_DOCS)
find_package(Doxygen)
if( DOXYGEN_FOUND )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(docs ALL
${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
VERBATIM
)
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/${PROJECT_NAME} DESTINATION doc)
endif()
endif()
# generates the find_package file for the h2sl project
configure_file(${PROJECT_SOURCE_DIR}/Find${PROJECT_NAME}.cmake.in ${CMAKE_BINARY_DIR}/Find${PROJECT_NAME}.cmake @ONLY)
install(FILES
${CMAKE_BINARY_DIR}/Find${PROJECT_NAME}.cmake
DESTINATION
${CMAKE_INSTALL_PREFIX}/share/cmake-${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}/Modules/)
# add the source directories
foreach(dir ${DIRS})
add_subdirectory(${dir})
endforeach(dir ${DIRS})