1 cmake_minimum_required(VERSION 3.1)
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 if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
25 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
29 add_custom_target(info ALL)
30 add_custom_target(html)
31 add_custom_target(pdf)
33 set (CMAKE_CXX_STANDARD 11)
35 find_package(CLN 1.2.2 REQUIRED)
36 include_directories(${CLN_INCLUDE_DIR})
38 include(CheckIncludeFile)
39 check_include_file("unistd.h" HAVE_UNISTD_H)
41 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/ginac)
43 # This macro implements some very special logic how to deal with the cache.
44 # By default the various install locations inherit their value from their
45 #"parent" variable, so if you set CMAKE_INSTALL_PREFIX, then
46 # EXEC_INSTALL_PREFIX, BIN_INSTALL_DIR, LIB_INSTALL_DIR, etc will calculate
47 # their value by appending subdirs to CMAKE_INSTALL_PREFIX.
48 # This would work just fine without using the cache.
49 # But if somebody wants e.g. a different EXEC_INSTALL_PREFIX this value
50 # has to go into the cache, otherwise it will be forgotten on the next cmake
51 # run. Once a variable is in the cache, it doesn't depend on its "parent"
52 # variables anymore and you can only change it by editing it directly.
53 # This macro helps in this regard, because as long as you don't set one
54 # of the variables explicitly to some location, the value will be computed
55 # from parents of the variable in question. So modifying CMAKE_INSTALL_PREFIX
56 # later on will have the desired effect.
57 # But once you decide to set e.g. EXEC_INSTALL_PREFIX to some special
58 # location this will go into the cache and it will no longer depend on
59 # CMAKE_INSTALL_PREFIX.
61 macro(_set_fancy _var _value _comment)
62 set(predefinedvalue "${_value}")
63 if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "${GINAC_INSTALL_DIR}" AND DEFINED GINAC_${_var})
64 set(predefinedvalue "${GINAC_${_var}}")
66 if (NOT DEFINED ${_var})
67 set(${_var} ${predefinedvalue})
69 set(${_var} "${${_var}}" CACHE PATH "${_comment}")
73 _set_fancy(EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
74 "Base directory for libraries and executables")
75 _set_fancy(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib"
76 "Libraries installation directory")
77 _set_fancy(BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin"
78 "Binaries installation directory")
79 _set_fancy(SHARE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/share"
80 "Base directory for architecture independent files")
81 _set_fancy(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include"
82 "Headers installation directory")
84 if (NOT DEFINED BUILD_SHARED_LIBS)
86 set(BUILD_SHARED_LIBS true)
88 set(BUILD_SHARED_LIBS false)
92 # Set proper rpath so tools will Just Work(TM) after make install.
93 # Also take care to add -Wl,-rpath, stanza into the *.pc file so that
95 # g++ `pkg-config --cflags --libs ginac`
97 # will Just Work (TM), too.
98 # Distro packagers should use -DCMAKE_INSTALL_RPATH="" to avoid
99 # setting rpath on installed binaries.
101 # rpath for making binaries/libraries relocatable
102 set(_ginac_rpath_reloc "$ORIGIN/../lib")
103 set(_wl_rpath "${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}")
105 # rpath for the pkg-config meta-data.
106 set(_ginaclib_rpath "${_wl_rpath}${_ginac_rpath_reloc}")
107 list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${LIB_INSTALL_DIR}" isSystemDir)
108 if ("${isSystemDir}" STREQUAL "-1")
109 list(APPEND _ginaclib_rpath "${_wl_rpath}\${libdir}")
112 if (NOT CMAKE_SKIP_RPATH)
114 set(GINACLIB_RPATH "${_ginaclib_rpath}")
118 configure_file(${CMAKE_SOURCE_DIR}/ginac.pc.cmake ${CMAKE_BINARY_DIR}/ginac.pc @ONLY)
119 install(FILES ${CMAKE_BINARY_DIR}/ginac.pc DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
121 # rpath for libginac.so itself, ginsh, and friends
122 set(_ginac_rpath ${_ginac_rpath_reloc})
123 foreach(_d ${CLN_LIBRARY_DIRS} ${LIB_INSTALL_DIR})
124 list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${_d}" isSystemDir)
125 if ("${isSystemDir}" STREQUAL "-1")
126 list(APPEND _ginac_rpath "${_d}")
129 list(REMOVE_DUPLICATES _ginac_rpath)
130 string(REPLACE ";" ":" ginac_rpath "${_ginac_rpath}")
132 if (NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_RPATH)
133 set(CMAKE_INSTALL_RPATH_USE_LINK_RPATH TRUE)
135 if (NOT DEFINED CMAKE_INSTALL_RPATH)
136 set(CMAKE_INSTALL_RPATH ${ginac_rpath})
138 if (APPLE AND NOT DEFINED CMAKE_INSTALL_NAME_DIR)
139 set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
142 list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${LIB_INSTALL_DIR}" isSystemDir)
143 if ("${isSystemDir}" STREQUAL "-1")
144 string(REPLACE ":" ";" _install_rpath "${CMAKE_INSTALL_RPATH}")
145 list(FIND _install_rpath "${LIB_INSTALL_DIR}" _is_rpath_consistent)
146 if ("${_is_rpath_consistent}" STREQUAL "-1")
147 message(WARNING "the libginac.so library will be installed into "
148 "a non-standard directory (${LIB_INSTALL_DIR}), "
149 "however, the rpath (${_install_rpath}) "
150 "does not contain that directory. Most likely "
151 "things won't work without extra configuration "
152 "(tweaking LD_LIBRARY_PATH, /etc/ld.so.conf, etc).")
161 find_package(Readline)
163 set(HAVE_LIBREADLINE 1)
164 set(HAVE_READLINE_READLINE_H 1)
165 set(HAVE_READLINE_HISTORY_H 1)
173 find_program(MAKEINFO makeinfo)
174 find_program(FIG2DEV fig2dev)
175 find_program(PYTHON python)
177 find_program(PYTHON python3)
180 message(FATAL_ERROR "Python version 3 or 2 is required")
184 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
185 add_definitions(-DHAVE_CONFIG_H)
188 set (LIBEXECDIR "${CMAKE_INSTALL_PREFIX}/libexec")
191 add_subdirectory(ginac)
192 add_subdirectory(tools)
193 add_subdirectory(check)
194 if (BISON_FOUND AND FLEX_FOUND)
195 add_subdirectory(ginsh)
198 add_subdirectory(doc)