]> www.ginac.de Git - ginac.git/blob - CMakeLists.txt
[build] Fix CMake build.
[ginac.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
3
4 project(GiNaC)
5 file(STRINGS ${CMAKE_SOURCE_DIR}/ginac/version.h _ginac_vinfo REGEX "^#define[\t ]+GINACLIB_.*_VERSION.*")
6 string(REGEX REPLACE "^.*GINACLIB_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" GINAC_MAJOR_VERSION "${_ginac_vinfo}")
7 string(REGEX REPLACE "^.*GINACLIB_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" GINAC_MINOR_VERSION "${_ginac_vinfo}")
8 string(REGEX REPLACE "^.*GINACLIB_MICRO_VERSION[ \t]+([0-9]+).*" "\\1" GINAC_MICRO_VERSION "${_ginac_vinfo}")
9 set(GINAC_VERSION "${GINAC_MAJOR_VERSION}.${GINAC_MINOR_VERSION}.${GINAC_MICRO_VERSION}")
10
11 # Library versioning info
12 file(STRINGS ${CMAKE_SOURCE_DIR}/ginac/version.h _ginac_vinfo REGEX "^#define[\t ]+GINAC_LT_.*")
13 string(REGEX REPLACE "^.*GINAC_LT_CURRENT[ \t]+([0-9]+).*" "\\1" ginac_lt_current "${_ginac_vinfo}")
14 string(REGEX REPLACE "^.*GINAC_LT_AGE[ \t]+([0-9]+).*" "\\1" ginac_lt_age "${_ginac_vinfo}")
15 string(REGEX REPLACE "^.*GINAC_LT_REVISION[ \t]+([0-9]+).*" "\\1" ginac_lt_revision "${_ginac_vinfo}")
16 # XXX: it looks like we need to set this for every platform?
17 math(EXPR ginaclib_soversion "${ginac_lt_current} - ${ginac_lt_age}")
18 set(ginaclib_version ${ginaclib_soversion}.${ginac_lt_age}.${ginac_lt_revision})
19
20 # make check
21 enable_testing()
22 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
23 # make info
24 add_custom_target(info ALL)
25 add_custom_target(html)
26 add_custom_target(pdf)
27
28 find_package(CLN 1.2.2 REQUIRED)
29 include_directories(${CLN_INCLUDE_DIR})
30
31 include(CheckIncludeFile)
32 check_include_file("unistd.h" HAVE_UNISTD_H)
33
34 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/ginac)
35
36 # This macro implements some very special logic how to deal with the cache.
37 # By default the various install locations inherit their value from their
38 #"parent" variable, so if you set CMAKE_INSTALL_PREFIX, then
39 # EXEC_INSTALL_PREFIX, BIN_INSTALL_DIR, LIB_INSTALL_DIR, etc will calculate
40 # their value by appending subdirs to CMAKE_INSTALL_PREFIX.
41 # This would work just fine without using the cache.
42 # But if somebody wants e.g. a different EXEC_INSTALL_PREFIX this value
43 # has to go into the cache, otherwise it will be forgotten on the next cmake
44 # run. Once a variable is in the cache, it doesn't depend on its "parent"
45 # variables anymore and you can only change it by editing it directly.
46 # This macro helps in this regard, because as long as you don't set one
47 # of the variables explicitly to some location, the value will be computed
48 # from parents of the variable in question. So modifying CMAKE_INSTALL_PREFIX
49 # later on will have the desired effect.
50 # But once you decide to set e.g. EXEC_INSTALL_PREFIX to some special
51 # location this will go into the cache and it will no longer depend on
52 # CMAKE_INSTALL_PREFIX.
53
54 macro(_set_fancy _var _value _comment)
55         set(predefinedvalue "${_value}")
56         if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "${GINAC_INSTALL_DIR}" AND DEFINED GINAC_${_var})
57                 set(predefinedvalue "${GINAC_${_var}}")
58         endif()
59         if (NOT DEFINED ${_var})
60                 set(${_var} ${predefinedvalue})
61         else()
62                 set(${_var} "${${_var}}" CACHE PATH "${_comment}")
63         endif()
64 endmacro(_set_fancy)
65
66 _set_fancy(EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
67            "Base directory for libraries and executables")
68 _set_fancy(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib"
69            "Libraries installation directory")
70 _set_fancy(BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin"
71            "Binaries installation directory")
72 _set_fancy(SHARE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/share"
73            "Base directory for architecture independent files")
74 _set_fancy(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include"
75            "Headers installation directory")
76
77 if (NOT DEFINED BUILD_SHARED_LIBS)
78         if (NOT MSVC)
79                 set(BUILD_SHARED_LIBS true)
80         else()
81                 set(BUILD_SHARED_LIBS false)
82         endif()
83 endif()
84
85 # Set proper rpath so tools will Just Work(TM) after make install.
86 # Also take care to add -Wl,-rpath, stanza into the *.pc file so that
87 #
88 # g++ `pkg-config --cflags --libs ginac`
89 #
90 # will Just Work (TM), too.
91 # Distro packagers should use -DCMAKE_INSTALL_RPATH="" to avoid
92 # setting rpath on installed binaries.
93
94 # rpath for making binaries/libraries relocatable
95 set(_ginac_rpath_reloc "$ORIGIN/../lib")
96 set(_wl_rpath "${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}")
97
98 # rpath for the pkg-config meta-data.
99 set(_ginaclib_rpath "${_wl_rpath}${_ginac_rpath_reloc}")
100 list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${LIB_INSTALL_DIR}" isSystemDir)
101 if ("${isSystemDir}" STREQUAL "-1")
102         list(APPEND _ginaclib_rpath "${_wl_rpath}\${libdir}")
103 endif()
104 set(GINACLIB_RPATH)
105 if (NOT CMAKE_SKIP_RPATH)
106         if (_wl_rpath)
107                 set(GINACLIB_RPATH "${_ginaclib_rpath}")
108         endif()
109 endif()
110
111 configure_file(${CMAKE_SOURCE_DIR}/ginac.pc.cmake ${CMAKE_BINARY_DIR}/ginac.pc @ONLY)
112 install(FILES ${CMAKE_BINARY_DIR}/ginac.pc DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
113
114 # rpath for libginac.so itself, ginsh, and friends
115 set(_ginac_rpath ${_ginac_rpath_reloc})
116 foreach(_d ${CLN_LIBRARY_DIRS} ${LIB_INSTALL_DIR})
117         list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${_d}" isSystemDir)
118         if ("${isSystemDir}" STREQUAL "-1")
119                 list(APPEND _ginac_rpath "${_d}")
120         endif()
121 endforeach()
122 list(REMOVE_DUPLICATES _ginac_rpath)
123 string(REPLACE ";" ":" ginac_rpath "${_ginac_rpath}")
124
125 if (NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_RPATH)
126         set(CMAKE_INSTALL_RPATH_USE_LINK_RPATH TRUE)
127 endif()
128 if (NOT DEFINED CMAKE_INSTALL_RPATH)
129         set(CMAKE_INSTALL_RPATH ${ginac_rpath})
130 endif()
131 if (APPLE AND NOT DEFINED CMAKE_INSTALL_NAME_DIR)
132         set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
133 endif()
134
135 list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${LIB_INSTALL_DIR}" isSystemDir)
136 if ("${isSystemDir}" STREQUAL "-1")
137         string(REPLACE ":" ";" _install_rpath "${CMAKE_INSTALL_RPATH}")
138         list(FIND _install_rpath "${LIB_INSTALL_DIR}" _is_rpath_consistent)
139         if ("${_is_rpath_consistent}" STREQUAL "-1")
140                 message(WARNING "the libginac.so library will be installed into "
141                                 "a non-standard directory (${LIB_INSTALL_DIR}), "
142                                 "however, the rpath (${_install_rpath}) "
143                                 "does not contain that directory. Most likely "
144                                 "things won't work without extra configuration "
145                                 "(tweaking LD_LIBRARY_PATH, /etc/ld.so.conf, etc).")
146         endif()
147 endif()
148
149
150 include(FindFLEX)
151 include(FindBISON)
152 find_package(BISON)
153 find_package(FLEX)
154 find_package(Readline)
155 if (READLINE_FOUND)
156         set(HAVE_LIBREADLINE 1)
157         set(HAVE_READLINE_READLINE_H 1)
158         set(HAVE_READLINE_HISTORY_H 1)
159 endif()
160
161 find_package(LibDL)
162 if (LIBDL_FOUND)
163         set(HAVE_LIBDL 1)
164 endif()
165
166 find_program(MAKEINFO makeinfo)
167 find_program(FIG2DEV fig2dev)
168
169 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
170 add_definitions(-DHAVE_CONFIG_H)
171
172 add_subdirectory(ginac)
173 add_subdirectory(tools)
174 add_subdirectory(check)
175 if (BISON_FOUND AND FLEX_FOUND)
176         add_subdirectory(ginsh)
177 endif()
178 if (MAKEINFO)
179         add_subdirectory(doc)
180 endif()
181