1 cmake_minimum_required(VERSION 2.6)
2 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
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}")
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})
22 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
24 add_custom_target(info ALL)
25 add_custom_target(html)
26 add_custom_target(pdf)
28 find_package(CLN 1.2.2 REQUIRED)
29 include_directories(${CLN_INCLUDE_DIR})
31 include(CheckIncludeFile)
32 check_include_file("stdint.h" HAVE_STDINT_H)
33 check_include_file("unistd.h" HAVE_UNISTD_H)
35 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/ginac)
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.
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}}")
60 if (NOT DEFINED ${_var})
61 set(${_var} ${predefinedvalue})
63 set(${_var} "${${_var}}" CACHE PATH "${_comment}")
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")
78 if (NOT DEFINED BUILD_SHARED_LIBS)
80 set(BUILD_SHARED_LIBS true)
82 set(BUILD_SHARED_LIBS false)
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
89 # g++ `pkg-config --cflags --libs ginac`
91 # will Just Work (TM), too.
92 # Distro packagers should use -DCMAKE_INSTALL_RPATH="" to avoid
93 # setting rpath on installed binaries.
95 # rpath for making binaries/libraries relocatable
96 set(_ginac_rpath_reloc "$ORIGIN/../lib")
97 set(_wl_rpath "${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}")
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}")
106 if (NOT CMAKE_SKIP_RPATH)
108 set(GINACLIB_RPATH "${_ginaclib_rpath}")
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")
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}")
123 list(REMOVE_DUPLICATES _ginac_rpath)
124 string(REPLACE ";" ":" ginac_rpath "${_ginac_rpath}")
126 if (NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_RPATH)
127 set(CMAKE_INSTALL_RPATH_USE_LINK_RPATH TRUE)
129 if (NOT DEFINED CMAKE_INSTALL_RPATH)
130 set(CMAKE_INSTALL_RPATH ${ginac_rpath})
132 if (APPLE AND NOT DEFINED CMAKE_INSTALL_NAME_DIR)
133 set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
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).")
155 find_package(Readline)
157 set(HAVE_LIBREADLINE 1)
158 set(HAVE_READLINE_READLINE_H 1)
159 set(HAVE_READLINE_HISTORY_H 1)
167 find_program(MAKEINFO makeinfo)
168 find_program(FIG2DEV fig2dev)
170 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
171 add_definitions(-DHAVE_CONFIG_H)
173 add_subdirectory(ginac)
174 add_subdirectory(tools)
175 add_subdirectory(check)
176 if (BISON_FOUND AND FLEX_FOUND)
177 add_subdirectory(ginsh)
180 add_subdirectory(doc)