Skip to content

Commit fd20220

Browse files
committed
Reupload CMake buildsystem
1 parent 3d6fd18 commit fd20220

20 files changed

+1647
-0
lines changed

CMakeLists.txt

Lines changed: 362 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,362 @@
1+
2+
3+
4+
#[[====================== Top-Level CMakeLists.txt ======================]]
5+
6+
7+
#[[
8+
9+
The CMake Build system design original is from "tueda/form --branch=appveyor" and
10+
redesign/expand functionality by TaiXeflar on "TaiXeflar/form".
11+
12+
The expanded CMake Build system sources, include CMakeLists.txt, Repo contained CMake modules,
13+
CMake insert files are under the GNU GPL v3.0 License which follows the vermaseren/form project license.
14+
15+
]]
16+
17+
#[[
18+
19+
Copyright (C) 1984-2023 J.A.M. Vermaseren
20+
When using this file you are requested to refer to the publication
21+
J.A.M. Vermaseren "New features of FORM" math-ph/0010025
22+
This is considered a matter of courtesy as the development was paid
23+
for by FOM the Dutch physics granting agency and we would like to
24+
be able to track its scientific use to convince FOM of its value
25+
for the community.
26+
27+
FORM is free software: you can redistribute it and/or modify it under the
28+
terms of the GNU General Public License as published by the Free Software
29+
Foundation, either version 3 of the License, or (at your option) any later
30+
version.
31+
32+
FORM is distributed in the hope that it will be useful, but WITHOUT ANY
33+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
35+
details.
36+
37+
You should have received a copy of the GNU General Public License along
38+
with FORM. If not, see <http://www.gnu.org/licenses/>.
39+
40+
]]
41+
42+
43+
# Upgrade CMake min. version to 3.28.
44+
cmake_minimum_required(VERSION 3.28)
45+
46+
# Set Repo cmake modules append to CMake self existed modules for global call.
47+
#set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR}/cmake/modules")
48+
49+
# Set CMake Policy for CMake Behavior.
50+
include(cmake/CMakePolicy.cmake)
51+
52+
53+
# Defines Form Project's cmake modules directory.
54+
55+
# check for if cmake command contains with Autoconf generated "configure" script alias.
56+
include(cmake/check4_Autoconf.cmake)
57+
58+
# Extract Form version number from form3.h; else if no define then extract from Top-Level CMakeLists.txt.
59+
set(FORM3_H sources/form3.h)
60+
file(READ ${FORM3_H} FORM3_H_CONTENT)
61+
if(NOT DEFINED FORM_MAJOR_VERSION)
62+
string(REGEX REPLACE "#define *MAJORVERSION *" "" MAJOR_VERSION "${FORM3_H_CONTENT}")
63+
if(DEFINED CMAKE_MATCH_1)
64+
set(FORM_MAJOR_VERSION ${MAJOR_VERSION})
65+
else()
66+
set(FORM_MAJOR_VERSION 5)
67+
endif()
68+
endif()
69+
if(NOT DEFINED FORM_MINOR_VERSION)
70+
string(REGEX REPLACE "#define *MINORVERSION *" "" MINOR_VERSION "${FORM3_H_CONTENT}")
71+
if(DEFINED CMAKE_MATCH_1)
72+
set(FORM_MINOR_VERSION ${MINOR_VERSION})
73+
else()
74+
set(FORM_MINOR_VERSION 0)
75+
endif()
76+
endif()
77+
if(NOT DEFINED FORM_PATCH_VERSION)
78+
string(REGEX REPLACE "#define *PATCHVERSION *" "" PATCH_VERSION "${FORM3_H_CONTENT}")
79+
if(DEFINED CMAKE_MATCH_1)
80+
set(FORM_PATCH_VERSION ${PATCH_VERSION})
81+
else()
82+
set(FORM_PATCH_VERSION 0)
83+
endif()
84+
endif()
85+
if(NOT DEFINED FORM_IS_BETA_VERSION)
86+
set(FORM_IS_BETA_VERSION TRUE) # <--------- If is Beta, Switch this boolean to TRUE.
87+
if(${FORM_IS_BETA_VERSION})
88+
set(FORM_BETA_TAG "-beta1") # <--------- If define is Beta version, put beta version tag here.
89+
endif()
90+
endif()
91+
92+
93+
# Project starts here.
94+
# Add Define of Symbolic Form as C/C++ language.
95+
project(Form
96+
VERSION ${FORM_MAJOR_VERSION}.${FORM_MINOR_VERSION}.${FORM_PATCH_VERSION}
97+
LANGUAGES C CXX)
98+
include(CheckCSourceCompiles)
99+
include(CheckIncludeFileCXX)
100+
include(CheckTypeSize)
101+
102+
include(cmake/check4VersionH.cmake)
103+
104+
105+
# Set CMake Build-Out-Of-Source Rules.
106+
if(${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
107+
message(WARNING "Detected building in source dir!")
108+
message("CMAKE Presents Build out of source.")
109+
message("You can either mkdir \"build\" or passing \"-B<BUILD_DIR>\" to build.")
110+
message(FATAL_ERROR "Throwback Build error in source dir!")
111+
endif()
112+
if(EXISTS "${CMAKE_SOURCE_DIR}/CMakeFiles")
113+
message(FATAL_ERROR "Please remove \"CMakeFiles/\" folder in source dir!")
114+
endif()
115+
if(EXISTS "${CMAKE_SOURCE_DIR}/CMakeCache.txt")
116+
message(FATAL_ERROR "Please remove \"CMakeCache.txt\" in source dir!")
117+
endif()
118+
119+
# Define the "--prefix" replaced option "INSTALL".
120+
message(CHECK_START "Check for Install Prefix")
121+
if((NOT DEFINED INSTALL) OR (${CMAKE_INSTALL_PREFIX} MATCHES "^(default|Default|guess)$"))
122+
message(CHECK_FAIL "Not set: Install in default directory ${CMAKE_INSTALL_PREFIX}")
123+
elseif(DEFINED INSTALL)
124+
set(CMAKE_INSTALL_PREFIX ${INSTALL} CACHE STRING "Customized Install Directory")
125+
message(CHECK_PASS "${INSTALL}")
126+
endif()
127+
128+
# [Tueda]
129+
# Check for data model.
130+
message(CHECK_START "Check for data model")
131+
check_type_size(char SIZEOF_CHAR)
132+
check_type_size(short SIZEOF_SHORT)
133+
check_type_size(int SIZEOF_INT)
134+
check_type_size(long SIZEOF_LONG)
135+
check_type_size("long long" SIZEOF_LONG_LONG)
136+
check_type_size(void* SIZEOF_VOID_P)
137+
138+
set(sizeof_types "${SIZEOF_CHAR}-${SIZEOF_SHORT}-${SIZEOF_INT}-${SIZEOF_LONG}-${SIZEOF_LONG_LONG}-${SIZEOF_VOID_P}")
139+
140+
if(sizeof_types MATCHES "1-2-4-4-8-4")
141+
set(ILP32 TRUE)
142+
set(data_model "ILP32")
143+
elseif(sizeof_types MATCHES "1-2-4-4-8-8")
144+
set(LLP64 TRUE)
145+
set(data_model "LLP64")
146+
elseif(sizeof_types MATCHES "1-2-4-8-8-8")
147+
set(LP64 TRUE)
148+
set(data_model "LP64")
149+
else()
150+
message(FATAL_ERROR "Data model ${sizeof_types} not supported")
151+
endif()
152+
message(CHECK_PASS "${sizeof_types} (${data_model})")
153+
154+
155+
# [Tueda]
156+
# Check for "inline" keyword in C.
157+
function(check_c_inline)
158+
unset(inline PARENT_SCOPE)
159+
foreach(inline_keyword "inline" "__inline__" "__inline")
160+
string(TOUPPER "HAVE_C_${inline_keyword}" value)
161+
check_c_source_compiles("
162+
typedef int foo_t;
163+
static ${inline_keyword} foo_t static_foo() { return 0; }
164+
${inline_keyword} foo_t foo() { return 0; }
165+
int main() { return 0; }
166+
" ${value})
167+
if(${value})
168+
if("${inline_keyword}" STREQUAL "inline")
169+
else()
170+
set(inline "${inline_keyword}" PARENT_SCOPE)
171+
endif()
172+
return()
173+
endif()
174+
endforeach()
175+
set(inline " " PARENT_SCOPE)
176+
endfunction()
177+
178+
check_c_inline()
179+
180+
# [Tueda]
181+
# Check for header files.
182+
check_include_file_cxx(boost/unordered_map.hpp HAVE_BOOST_UNORDERED_MAP_HPP)
183+
check_include_file_cxx(boost/unordered_set.hpp HAVE_BOOST_UNORDERED_SET_HPP)
184+
check_include_file_cxx(tr1/unordered_map HAVE_TR1_UNORDERED_MAP)
185+
check_include_file_cxx(tr1/unordered_set HAVE_TR1_UNORDERED_SET)
186+
check_include_file_cxx(unordered_map HAVE_UNORDERED_MAP)
187+
check_include_file_cxx(unordered_set HAVE_UNORDERED_SET)
188+
189+
# % Taixeflar
190+
# Add form build control flags. ----> Form/TForm/PForm
191+
message(CHECK_START "Checking for Sequential Form build")
192+
if(NOT DEFINED BUILD_FORM)
193+
set(BUILD_FORM TRUE CACHE BOOL "Enable build Form")
194+
message(CHECK_PASS "ON")
195+
elseif(NOT ${BUILD_FORM})
196+
message(CHECK_PASS "OFF")
197+
elseif(${BUILD_FORM})
198+
message(CHECK_PASS "ON")
199+
endif()
200+
201+
message(CHECK_START "Checking for Thread version Form build")
202+
if(NOT DEFINED BUILD_TFORM)
203+
set(BUILD_TFORM OFF CACHE BOOL "Enable build Thread Form")
204+
message(CHECK_PASS "Not set")
205+
elseif(${BUILD_TFORM})
206+
message(CHECK_PASS "ON")
207+
elseif(NOT ${BUILD_TFORM})
208+
message(CHECK_PASS "OFF")
209+
endif()
210+
211+
message(CHECK_START "Checking for MPI version Form build")
212+
if(NOT DEFINED BUILD_PFORM)
213+
set(BUILD_PFORM OFF CACHE BOOL "Enable build Parallel Form")
214+
message(CHECK_PASS "Not set")
215+
elseif(${BUILD_PFORM})
216+
message(CHECK_PASS "ON")
217+
include(FindMPI)
218+
elseif(NOT ${BUILD_PFORM})
219+
message(CHECK_PASS "OFF")
220+
endif()
221+
222+
# Check for linking Libraries.
223+
message(STATUS "Check for 3rd-party link options.")
224+
225+
# Enabling with POSIX Threads library on TForm.
226+
message(CHECK_START "Check for pthreads for tform.")
227+
if(NOT ${BUILD_TFORM})
228+
message(CHECK_PASS "Skip")
229+
elseif(${BUILD_TFORM})
230+
if(${UNIX})
231+
find_package(Threads REQUIRED)
232+
if(${THREADS_FOUND})
233+
message(CHECK_PASS "Found")
234+
else()
235+
message(CHECK_FAIL "Failed")
236+
endif()
237+
elseif(${WINDOWS})
238+
include(cmake/modules/FindPThread4w.cmake)
239+
endif()
240+
endif()
241+
242+
243+
# Enable linking with zlib.
244+
message(CHECK_START "Linking ZLIB")
245+
if(NOT DEFINED WITH_ZLIB)
246+
set(WITH_ZLIB OFF CACHE BOOL "Form Linking with zlib")
247+
message(CHECK_PASS "Not set")
248+
elseif(${WITH_ZLIB})
249+
message(CHECK_PASS "ON")
250+
find_package(ZLIB REQUIRED)
251+
include_directories(${ZLIB_INCLUDE_DIR})
252+
elseif(NOT ${WITH_ZLIB})
253+
message(CHECK_PASS "OFF")
254+
endif()
255+
# Enable linking with zstd.
256+
message(CHECK_START "Linking ZSTD")
257+
if(NOT DEFINED WITH_ZSTD)
258+
set(WITH_ZSTD OFF CACHE BOOL "Form Linking with zstd")
259+
message(CHECK_PASS "Not set")
260+
elseif(${WITH_ZSTD})
261+
message(CHECK_PASS "ON")
262+
find_package(Zstd REQUIRED)
263+
include_directories(${ZSTD_INCLUDE_DIR})
264+
elseif(NOT ${WITH_ZSTD})
265+
message(CHECK_PASS "OFF")
266+
endif()
267+
# Enable linking with GNU Multiple Precision Arithmetic Library(GMP).
268+
message(CHECK_START "Linking GMP")
269+
if(NOT DEFINED WITH_GMP)
270+
set(WITH_GMP OFF CACHE BOOL "Form Linking with GMP library")
271+
message(CHECK_PASS "Not Set")
272+
elseif(${WITH_GMP})
273+
message(CHECK_PASS "ON")
274+
if(${MSVC})
275+
message(AUTHOR_WARNING
276+
"Warning: You are using MSVC to link with GMP libraries.
277+
Please make sure the MSVC can identify GMP libraries with name `libgmp.lib`.")
278+
endif()
279+
include(cmake/modules/FindGMP.cmake)
280+
include_directories(${GMP_INCLUDE_DIR})
281+
elseif(NOT ${WITH_GMP})
282+
message(CHECK_PASS "OFF")
283+
endif()
284+
# Enable Linking with MPFR.
285+
message(CHECK_START "Linking MPFR")
286+
if(NOT DEFINED WITH_MPFR)
287+
set(WITH_MPFR OFF CACHE BOOL "Form Linking with MPFR Library")
288+
message(CHECK_PASS "Not set")
289+
elseif(${WITH_MPFR})
290+
message(CHECK_PASS "ON")
291+
if(${MSVC})
292+
message(AUTHOR_WARNING
293+
"Warning: You are using MSVC to link with MPFR libraries.
294+
Please make sure the MSVC can identify MPFR libraries with name `libmpfr.lib`.")
295+
endif()
296+
include(cmake/modules/FindMPFR.cmake)
297+
include_directories(${MPFR_INCLUDE_DIR})
298+
elseif(NOT ${WITH_MPFR})
299+
message(CHECK_PASS "OFF")
300+
endif()
301+
302+
message(CHECK_START "Linking shared/static libraries")
303+
if(NOT DEFINED SHARE_LIB)
304+
set(SHARE_LIB OFF CACHE BOOL "Form Build linking with Shared/Static Libraries")
305+
message(CHECK_FAIL "Not set")
306+
elseif(NOT ${SHARE_LIB})
307+
option(BUILD_SHARED_LIBS OFF)
308+
message(CHECK_PASS "STATIC")
309+
elseif(${SHARE_LIB})
310+
option(BUILD_SHARED_LIBS ON)
311+
message(CHECK_FAIL "SHARED")
312+
endif()
313+
314+
#[ Enable/Disable float support for FORM.
315+
# Set a AUTHOR_WARNING for only developers to mension the error occurs on compiling with enable float.
316+
# Remove this after problems solved.
317+
message(CHECK_START "Enable float options")
318+
if(NOT DEFINED WITH_FLOAT)
319+
set(WITH_FLOAT OFF CACHE BOOL "Enable build with float support")
320+
message(CHECK_PASS "Not set")
321+
elseif(${WITH_FLOAT})
322+
message(WARNING "Form build with float features forced turn ON.")
323+
message(STATUS "Starting find GMP and MPFR libraries.")
324+
include(cmake/modules/FindGMP.cmake)
325+
include(cmake/modules/FindMPFR.cmake)
326+
include_directories(${GMP_INCLUDR_DIR} ${MPFR_INCLUDE_DIR})
327+
message(AUTHOR_WARNING "
328+
Warning: WITH_FLOAT options will engage compile error issues.
329+
If you are not developing on this issue, please set \"WITH_FLOAT\" to 'off', but \"WITH_GMP\" and \"WITH_MPFR\" will not be set off automatically.
330+
If you want GMP and MPFR disabled with \"WITH_FLOAT\" switch off later, please pass \"-DWITH_GMP=OFF -DWITH_MPFR=OFF\", or regenerate buildfiles again by delete cmake generated files/folders'.
331+
")
332+
message(CHECK_PASS "ON")
333+
set(WITH_GMP ON)
334+
set(WITH_MPFR ON)
335+
elseif(NOT ${WITH_FLOAT})
336+
message(CHECK_PASS "OFF")
337+
endif()
338+
#]]
339+
340+
# Add build EnvModules for Form.
341+
message(CHECK_START "Enable Environment Modules file")
342+
if(NOT DEFINED WITH_MODULES)
343+
set(WITH_MODULES OFF CACHE BOOL "Enable build Modulefiles")
344+
message(CHECK_PASS "Not set")
345+
elseif(NOT ${WITH_MODULES})
346+
message(CHECK_PASS "Disabled")
347+
elseif(${WITH_MODULES})
348+
message(CHECK_PASS "Enabled")
349+
endif()
350+
351+
# Add build log printing flags.
352+
if(NOT DEFINED BUILDLOG)
353+
set(BUILDLOG ON CACHE BOOL "Print build information in default")
354+
message(STATUS "Enabled export build details during build.")
355+
elseif(NOT BUILDLOG)
356+
message(STATUS "Disabled export build log.")
357+
endif()
358+
359+
360+
361+
# Process subdirectories.
362+
add_subdirectory(sources)

cmake/CMakePolicy.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# Add CMake Policy for cmake behavior changes.
3+
4+
cmake_policy(SET CMP0000 NEW)
5+
# CMake projects requires `cmake_minimum_repuired(VERSION <MIN> .....)` in the head part of Top-Level CMakeLists.txt.
6+
7+
cmake_policy(SET CMP0012 NEW)
8+
#CMP0012 NEW encourage users to set CMake policy where if condition must have variable expanded inside.
9+
10+
cmake_policy(SET CMP0048 NEW)
11+
# Set CMake policy where project() have params 'VERSION' defined.
12+
13+
cmake_policy(SET CMP0025 NEW)
14+
cmake_policy(SET CMP0047 NEW)
15+
cmake_policy(SET CMP0089 NEW)
16+
# Set CMake policy where COMPILER_ID is ensured to write into the buildstamp.

0 commit comments

Comments
 (0)