CMakeLists.txt 6.66 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
# Copyright 2010, Olivier Stasse, JRL, CNRS/AIST
2
#
Thomas Moulard's avatar
Thomas Moulard committed
3
4
5
6
7
# This file is part of dynamic-graph.
# dynamic-graph is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
8
#
Thomas Moulard's avatar
Thomas Moulard committed
9
10
11
12
13
14
# dynamic-graph is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Lesser Public License for more details.  You should have
# received a copy of the GNU Lesser General Public License along with
# dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
15
16
17

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

18
SET(PROJECT_NAME dynamic-graph)
19
20
project(${PROJECT_NAME})

21
22
23
24
25
# --- PROJECT VERSION -----------------------
SET(${PROJECT_NAME}_VERSION_MAJOR "1")
SET(${PROJECT_NAME}_VERSION_MINOR "0")
SET(${PROJECT_NAME}_VERSION_PATCH "0")
SET(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}")
26
SET(PROJECT_VERSION ${${PROJECT_NAME}_VERSION}.99)
27
28
29

SET(CMAKE_VERBOSE_MAKEFILE true)

30
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
31
32
33
34
35
36
37

# Get the OS
SET(OS ${CMAKE_SYSTEM_NAME})

#----------------------------------------------------
# --- GENERIC FLAGS ---------------------------------
#----------------------------------------------------
38
39
40
# For CMAKE Modules
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")

41
# Specify the compile flags for the overall library.
42
43
44
45
46
47
48
49
50
51
52
53
IF(WIN32)
  SET(LIBDIR_KW "/LIBPATH:")
  SET(LIBINCL_KW "")
  SET(LIB_EXT ".lib")
ENDIF(WIN32)

IF(UNIX)
  SET(LIBDIR_KW "-L")
  SET(LIBINCL_KW "-l")
  SET(LIB_EXT "")
ENDIF(UNIX)

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Link flags
SET(${PROJECT_NAME}_LINK_SRC_FLAGS "")
SET(${PROJECT_NAME}_LINK_FLAGS "${LIBDIR_KW}${${PROJECT_NAME}_BINARY_DIR}/lib ")
SET(${PROJECT_NAME}_LINK_FLAGS "${${PROJECT_NAME}_LINK_FLAGS} ${LIBINCLUSION_KW}${${PROJECT_NAME}_INTERN_LIBS}${LIBINCLUSION_EXT}")
IF(UNIX)
  SET(${PROJECT_NAME}_LINK_SRC_FLAGS "${${PROJECT_NAME}_LINK_SRC_FLAGS} -ldl")
  SET(${PROJECT_NAME}_LINK_FLAGS "${${PROJECT_NAME}_LINK_FLAGS} -ldl")
ENDIF(UNIX)

# Release flags
IF(\"${CMAKE_BUILD_TYPE}\" STREQUAL \"\" )
ELSE(\"${CMAKE_BUILD_TYPE}\" STREQUAL \"\" )
  IF(${CMAKE_BUILD_TYPE} STREQUAL DEBUG)
    SET(${PROJECT_NAME}_CXXFLAGS ${CMAKE_CXX_FLAGS_DEBUG}) # Useless since CXX_FLAGS, not CXXFLAGS.
  ENDIF(${CMAKE_BUILD_TYPE} STREQUAL DEBUG)
  IF(${CMAKE_BUILD_TYPE} STREQUAL RELEASE)
    SET(${PROJECT_NAME}_CXXFLAGS ${CMAKE_CXX_FLAGS_RELEASE}) # Same here.
  ENDIF(${CMAKE_BUILD_TYPE} STREQUAL RELEASE)
ENDIF (\"${CMAKE_BUILD_TYPE}\" STREQUAL \"\")

# --- Default options -------------------------------------------------
OPTION(BUILD_SHARED_LIBS "Build ${PROJECT_NAME} with shared libraries." ON)
florent's avatar
florent committed
76
OPTION(GENERATE_DOC "Generate html documentation" ON)
77

Olivier Stasse's avatar
Olivier Stasse committed
78
79
# --- BOOST ---------------------------------------------------
SET(Boost_THREAD_FOUND 0)
80
FIND_PACKAGE(Boost COMPONENTS thread REQUIRED)
Olivier Stasse's avatar
Olivier Stasse committed
81
82
83
84
IF(Boost_THREAD_FOUND)
  #MESSAGE(STATUS "Boost_THREAD_LIBRARY:" ${Boost_THREAD_LIBRARY})
  #MESSAGE(STATUS "Boost_THREAD_LIBRARY_RELEASE:" ${Boost_THREAD_LIBRARY_RELEASE})
  #MESSAGE(STATUS "Boost_THREAD_LIBRARY_DEBUG:" ${Boost_THREAD_LIBRARY_DEBUG})
85
86
	
	ADD_DEFINITIONS(-DHAVE_LIBBOOST_THREAD)
Olivier Stasse's avatar
Olivier Stasse committed
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

  # Look for the type of pattern to find.
  SET(BOOST_PATTERN_TOFIND "")
  IF(${CMAKE_BUILD_TYPE} MATCHES RELEASE)
    SET(BOOST_PATTERN_TOFIND optimized)
  ENDIF(${CMAKE_BUILD_TYPE} MATCHES RELEASE)
  IF(${CMAKE_BUILD_TYPE} MATCHES DEBUG)
    SET(BOOST_PATTERN_TOFIND debug)
  ENDIF(${CMAKE_BUILD_TYPE} MATCHES DEBUG)

  IF(BOOST_PATTERN_TOFIND)
    SET(BOOST_THREAD_LIST_LENGTH 0)
    LIST(LENGTH Boost_THREAD_LIBRARY BOOST_THREAD_LIST_LENGTH)
    # Debug or optimized library.
    IF(${BOOST_THREAD_LIST_LENGTH} MATCHES 4)
      LIST(FIND Boost_THREAD_LIBRARY ${BOOST_PATTERN_TOFIND} BTLB_index)
      LIST(REMOVE_AT Boost_THREAD_LIBRARY ${BTLB_index})
      LIST(GET Boost_THREAD_LIBRARY ${BTLB_index} BOOST_THREAD_LIB_NAME)
    # Default strategy
    ELSE(${BOOST_THREAD_LIST_LENGTH} MATCHES 4)
      SET(BOOST_THREAD_LIB_NAME ${Boost_THREAD_LIBRARY})
    ENDIF(${BOOST_THREAD_LIST_LENGTH} MATCHES 4)
  # Default strategy
  ELSE(BOOST_PATTERN_TOFIND)
    SET(BOOST_THREAD_LIB_NAME  ${Boost_THREAD_LIBRARY})
  ENDIF(BOOST_PATTERN_TOFIND)

114
115
116
117
118
119
120
121
122
123
124
  # --- PTHREAD -------------------------------------------------------
  FIND_PACKAGE(PTHREAD REQUIRED)
  IF(PTHREAD_FOUND)
    ADD_DEFINITIONS(-DHAVE_PTHREAD)
    IF(UNIX)
    	ADD_DEFINITIONS(-pthread)
    ENDIF(UNIX)
    INCLUDE_DIRECTORIES(${PTHREAD_INCLUDE_DIRS})
	LINK_DIRECTORIES(${PTHREAD_LIBRARY_DIRS})
  ENDIF(PTHREAD_FOUND)
  
Olivier Stasse's avatar
Olivier Stasse committed
125
126
127
128
129
130
131
132
133
134
135
136
ELSE(Boost_THREAD_FOUND)
  MESSAGE("WARNING: Boost thread not found. Trying without the thread library")
  FIND_PACKAGE(Boost)
  IF(NOT Boost_FOUND)
	MESSAGE(SEND_ERROR "!! ERROR: Boost not found.")
  ENDIF(NOT Boost_FOUND)
ENDIF(Boost_THREAD_FOUND)
MESSAGE(STATUS "Boost thread lib name: ${BOOST_THREAD_LIB_NAME} ${Boost_THREAD_LIBRARY}")

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})

137
138
139
140
141
142
143
144
#
# Look for dependencies
#

# Load Pkgconfig macros
INCLUDE(FindPkgConfig)
SET(PACKAGE_REQUIREMENTS "")

145
146
147
148
# Documentation.
INCLUDE(cmake/doxygen.cmake)
_SETUP_PROJECT_DOCUMENTATION()

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#
# pkg-config file
#

SET(install_pkg_prefix "\${prefix}")
SET(install_pkg_exec_prefix "\${exec_prefix}")
SET(install_pkg_libdir "\${libdir}")
SET(install_pkg_datarootdir "\${datarootdir}")
SET(install_pkg_include_dir "\${includedir}")

IF(UNIX)
  SET (${PROJECT_NAME}_LDFLAGS "-Wl,-R${install_pkg_libdir} ${LIBINCL_KW}${PROJECT_NAME}${LIB_EXT} ${${PROJECT_NAME}_LDFLAGS}")
ENDIF(UNIX)

IF(WIN32)
  SET (${PROJECT_NAME}_LDFLAGS "${LIBINCL_KW}${PROJECT_NAME}${LIB_EXT} ${${PROJECT_NAME}_LDFLAGS}")
ENDIF(WIN32)

# Install the file in the appropriate place.
SET(install_libdir_pkgconfig ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)

170
171
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/dynamic-graph.pc.cmake
  ${CMAKE_CURRENT_BINARY_DIR}/dynamic-graph.pc)
172

173
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/dynamic-graph.pc
174
175
176
  DESTINATION ${install_libdir_pkgconfig}	
  PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)

177
178
179
180
181
182
183
184
185
186
# Uninstall target.
CONFIGURE_FILE(
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  IMMEDIATE @ONLY)

ADD_CUSTOM_TARGET(uninstall
  "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

# Testing 
187
188
ENABLE_TESTING()

189
190
191
192
IF(WIN32)
  ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS /wd4251 /wd4275 /wd4101 /wd4355")
ENDIF(WIN32)

193
194
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(include)
195
ADD_SUBDIRECTORY(tools)
196
ADD_SUBDIRECTORY(doc)
Francois Bleibel's avatar
Francois Bleibel committed
197
ADD_SUBDIRECTORY(unitTesting)