forked from scarrazza/apfel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
97 lines (76 loc) · 3.32 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# BASIC DEFINITIONS ========================================================================
# define minimum version of cmake
cmake_minimum_required (VERSION 3.5)
cmake_policy(SET CMP0086 OLD)
cmake_policy(SET CMP0078 OLD)
# define project name, version and its languages
project(apfel CXX Fortran)
set(apfel_VERSION 3.0.7)
# define c++ standard and issue all the warning demanded by this standard
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fPIC")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fPIC -cpp")
set(CMAKE_SHARED_LINKER_FLAGS -w)
if (NOT DEFINED CMAKE_MACOSX_RPATH)
set(CMAKE_MACOSX_RPATH 0)
endif()
# CONFIG SCRIPT =========================================================================
# Configuration script
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "${prefix}")
set(includedir "${prefix}/include")
set(libdir "${prefix}/lib")
set(PACKAGE_VERSION "${apfel_VERSION}")
configure_file("${PROJECT_SOURCE_DIR}/bin/apfel-config.in" "${PROJECT_SOURCE_DIR}/bin/apfel-config")
# Fortran wrappers =========================================================================
configure_file("${PROJECT_SOURCE_DIR}/include/APFEL/FortranWrappers.h.cmake" "${PROJECT_SOURCE_DIR}/include/APFEL/FortranWrappers.h")
# FINALIZE ==================================================================================
# LHAPDF
find_program(LHAPDF_CONFIG lhapdf-config)
if (LHAPDF_CONFIG)
exec_program(${LHAPDF_CONFIG}
ARGS --cxxflags
OUTPUT_VARIABLE LHAPDF_CXX_FLAGS
)
set(LHAPDF_CXX_FLAGS ${LHAPDF_CXX_FLAGS} CACHE STRING INTERNAL)
exec_program(${LHAPDF_CONFIG}
ARGS --ldflags
OUTPUT_VARIABLE LHAPDF_LIBRARIES
)
set(LHAPDF_LIBRARIES ${LHAPDF_LIBRARIES} CACHE STRING INTERNAL)
else(LHAPDF_CONFIG)
add_compile_definitions(NOLHAPDF)
message("LHAPDF not found!")
endif(LHAPDF_CONFIG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LHAPDF_CXX_FLAGS} -Wall -fPIC -Wunused")
# generate list of source files
file(GLOB_RECURSE source_files src/* ccwrap/*)
# Add swig subdirectory
add_subdirectory(pywrap)
add_library(apfel SHARED ${source_files})
# include directory
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/src)
# define libraries to be linked
target_link_libraries(apfel ${LHAPDF_LIBRARIES})
# build test codes
enable_testing()
add_subdirectory(examples)
# define target library
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
# install
install(TARGETS apfel
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib)
install(DIRECTORY include/APFEL DESTINATION include)
install(FILES ${PROJECT_SOURCE_DIR}/bin/apfel-config
${CMAKE_CURRENT_BINARY_DIR}/examples/CheckAPFEL ${CMAKE_CURRENT_BINARY_DIR}/examples/ListFunctions DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
find_package(Python3 REQUIRED)
execute_process(COMMAND "${Python3_EXECUTABLE}" -c "import sysconfig; print('${CMAKE_INSTALL_PREFIX}' + sysconfig.get_path('purelib').replace(sysconfig.get_path('data'), ''), end = '')" OUTPUT_VARIABLE PYTHON_INSTALLATION_PATH)
install(TARGETS _apfel DESTINATION "${PYTHON_INSTALLATION_PATH}")
install(FILES ${CMAKE_BINARY_DIR}/pywrap/apfel.py DESTINATION ${PYTHON_INSTALLATION_PATH})