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