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