CMakeLists.txt 5.93 KB
Newer Older
Remi Perenon's avatar
Remi Perenon committed
1
2
3
#################################
# Commad line arguments section
#################################
Remi Perenon's avatar
Remi Perenon committed
4
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
Remi Perenon's avatar
Remi Perenon committed
5
6
7
8
9
10

#################################
# Project section
#################################
# The project is declared. It is a Fortran project.
project(Python_API Fortran)
11
set(LIBRARY_NAME crysfml_api)
12
13
add_library(${LIBRARY_NAME} SHARED
  Extensions/API_init.f90
Elisa Rebolini's avatar
Elisa Rebolini committed
14
  Extensions/API_Atom_TypeDef.f90
15
16
  Extensions/API_Crystallographic_Symmetry.f90
  Extensions/API_Crystal_Metrics.f90
Elisa Rebolini's avatar
Elisa Rebolini committed
17
  Extensions/API_Diffraction_Patterns.f90
18
  Extensions/API_Error_Messages.f90
19
  Extensions/API_IO_Formats.f90
20
  Extensions/API_Reflections_Utilities.f90
21
  Extensions/API_Structure_Factors.f90
22
  Extensions/CFML_API_Calc_Powder_Pattern.f90
23
  Extensions/forpy_mod.f90)
Remi Perenon's avatar
Remi Perenon committed
24
25
26
27
28
29
30
31

# Forpy must be preprocessed
set_source_files_properties(forpy_mod.f90 PROPERTIES COMPILE_FLAG "-cpp")

#################################
# Dependencies section
#################################
# Add a dependency to crysfml_common to keep sure that the crysfml_common library will be built first.
Simon Ward's avatar
Simon Ward committed
32
# See https://gitlab.kitware.com/cmake/cmake/-/issues/19226 for linking
Remi Perenon's avatar
Remi Perenon committed
33
34
add_dependencies(${LIBRARY_NAME} crysfml_common)

Simon Ward's avatar
Simon Ward committed
35
set(COMPATIBLE_VERSIONS 3.10 3.9 3.8 3.7 3.6)
36
37
38
39
40
if (NOT PYTHON_INTERPRETER_PATH)
  set(Python_ADDITIONAL_VERSIONS ${COMPATIBLE_VERSIONS})
  find_package(PythonInterp REQUIRED)
  set(PYTHON_INTERPRETER_PATH ${PYTHON_EXECUTABLE})
  message(STATUS ${PYTHON_INTERPRETER_PATH})
Remi Perenon's avatar
Remi Perenon committed
41
else()
42
  message(STATUS "using Python interpreter provided with PYTHON_INTERPRETER_PATH variable: " ${PYTHON_INTERPRETER_PATH})
Remi Perenon's avatar
Remi Perenon committed
43
endif()
44

Simon Ward's avatar
Simon Ward committed
45
46
47
48
49
50
51
52
53
54
55
56
if(WIN32)
    if (NOT PYTHON_LIBRARY_PATH)
      set(Python_ADDITIONAL_VERSIONS ${COMPATIBLE_VERSIONS})
      find_package(PythonLibs REQUIRED)
      set(PYTHON_LIBRARY_PATH ${PYTHON_LIBRARY})
      message(STATUS ${PYTHON_LIBRARY_PATH})
    else()
      message(STATUS "Linking Python extension with provided PYTHON_LIBRARY_PATH variable: " ${PYTHON_LIBRARY_PATH})
    endif()
    add_library(Python3_LIB STATIC IMPORTED)
    set_property(TARGET Python3_LIB PROPERTY IMPORTED_LOCATION ${PYTHON_LIBRARY_PATH})
endif()
Remi Perenon's avatar
Remi Perenon committed
57

58
59
60
61
# Set -Wl,-undefined,dynamic_lookup to OTHER_LDFLAGS
# Set include and linking
include_directories(${CRYSFML_COMMON_MODULE_DIRECTORY})
target_link_libraries(${LIBRARY_NAME} crysfml_common)
Simon Ward's avatar
Simon Ward committed
62
63
# Fix a problem on Mac OS X when building shared libraries
if(APPLE)
64
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
Simon Ward's avatar
Simon Ward committed
65
66
elseif(WIN32)
    target_link_libraries(${LIBRARY_NAME} Python3_LIB)
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
endif()

# target_link_libraries(${LIBRARY_NAME} Python3_LIB)

# Set library extension
set_target_properties(${LIBRARY_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${LIBRARY_NAME})
set(LIBRARY_FILENAME "crysfml_api.so")
if(APPLE)
    set_target_properties(${LIBRARY_NAME} PROPERTIES SUFFIX ".so")
    set(LIBRARY_FILENAME "crysfml_api.so")
elseif(WIN32)
    set_target_properties(${LIBRARY_NAME} PROPERTIES SUFFIX ".pyd")
    set(LIBRARY_FILENAME "crysfml_api.pyd")
endif()

Remi Perenon's avatar
Remi Perenon committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#################################
# Documentation
#################################
find_package(Doxygen)
if (DOXYGEN_FOUND)
	set( DOXYGEN_OUTPUT_DIRECTORY doxygen )
	set( DOXYGEN_COLLABORATION_GRAPH YES )
	set( DOXYGEN_EXTRACT_ALL YES )
	set( DOXYGEN_CLASS_DIAGRAMS YES )
	set( DOXYGEN_HIDE_UNDOC_RELATIONS NO )
	set( DOXYGEN_HAVE_DOT YES )
	set( DOXYGEN_CLASS_GRAPH YES )
	set( DOXYGEN_CALL_GRAPH YES )
	set( DOXYGEN_CALLER_GRAPH YES )
	set( DOXYGEN_COLLABORATION_GRAPH YES )
	set( DOXYGEN_BUILTIN_STL_SUPPORT YES )
	set( DOXYGEN_EXTRACT_PRIVATE YES )
	set( DOXYGEN_EXTRACT_PACKAGE YES )
	set( DOXYGEN_EXTRACT_STATIC YES )
	set( DOXYGEN_EXTRACT_LOCALMETHODS YES )
	set( DOXYGEN_UML_LOOK YES )
	set( DOXYGEN_UML_LIMIT_NUM_FIELDS 50 )
	set( DOXYGEN_TEMPLATE_RELATIONS YES )
	set( DOXYGEN_DOT_GRAPH_MAX_NODES 100 )
	set( DOXYGEN_MAX_DOT_GRAPH_DEPTH 0 )
	set( DOXYGEN_DOT_TRANSPARENT YES )
108
	set( DOXYGEN_EXCLUDE_PATTERNS *.f90 )
Remi Perenon's avatar
Remi Perenon committed
109
110
111
112
113
	doxygen_add_docs( doxygen ${CMAKE_CURRENT_SOURCE_DIR} )
else (DOXYGEN_FOUND)
  message("Doxygen is not installed - no documentation will be generated")
endif (DOXYGEN_FOUND)

Remi Perenon's avatar
Remi Perenon committed
114

Remi Perenon's avatar
Remi Perenon committed
115
#################################
Remi Perenon's avatar
Remi Perenon committed
116
# Tests
Remi Perenon's avatar
Remi Perenon committed
117
#################################
Remi Perenon's avatar
Remi Perenon committed
118
119
120
121
122
123
124
# Add tests
add_test(NAME "Python_API_Tests" COMMAND ${PYTHON_INTERPRETER_PATH} -m unittest discover ${CMAKE_CURRENT_BINARY_DIR}/../Tests)
add_custom_target(Python_Files ALL
        COMMAND
        ${CMAKE_COMMAND} -E copy_directory
        ${CMAKE_CURRENT_SOURCE_DIR}/../Tests
        ${CMAKE_CURRENT_BINARY_DIR}/../Tests
Simon Ward's avatar
Simon Ward committed
125

Remi Perenon's avatar
Remi Perenon committed
126
127
128
129
        COMMAND
        ${CMAKE_COMMAND} -E copy_directory
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${CMAKE_CURRENT_BINARY_DIR}/../Tests/CFML_api
130
        )
Simon Ward's avatar
Simon Ward committed
131

132
133
134
135
add_dependencies(Python_Files ${LIBRARY_NAME})

if(NOT PYSETUP)
    add_custom_target(Python_SO_Files ALL
Remi Perenon's avatar
Remi Perenon committed
136
137
138
139
140
        COMMAND
        ${CMAKE_COMMAND} -E copy
        ${CMAKE_CURRENT_BINARY_DIR}/${LIBRARY_FILENAME}
        ${CMAKE_CURRENT_BINARY_DIR}/../Tests/CFML_api
        )
141
    add_dependencies(Python_SO_Files ${LIBRARY_NAME})
Simon Ward's avatar
Simon Ward committed
142
endif()
Remi Perenon's avatar
Remi Perenon committed
143

Remi Perenon's avatar
Remi Perenon committed
144
145
146
#################################
# Install section
#################################
Remi Perenon's avatar
Remi Perenon committed
147
148
149
150
151
152
153
# The rules for installing the library.
install(DIRECTORY "" DESTINATION ${PYTHON_API_PREFIX}/CFML_api FILES_MATCHING PATTERN "*.py" PATTERN "Extensions" EXCLUDE)
if(WIN32)
install(TARGETS ${LIBRARY_NAME} RUNTIME DESTINATION ${PYTHON_API_PREFIX}/CFML_api)
else()
install(TARGETS ${LIBRARY_NAME} LIBRARY DESTINATION ${PYTHON_API_PREFIX}/CFML_api)
endif()
Remi Perenon's avatar
Remi Perenon committed
154

Remi Perenon's avatar
Remi Perenon committed
155
# Installing example files
Remi Perenon's avatar
Remi Perenon committed
156
157
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Examples" DESTINATION ${PYTHON_API_PREFIX} FILES_MATCHING PATTERN "*.py")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Examples/Data" DESTINATION ${PYTHON_API_PREFIX}/Examples FILES_MATCHING PATTERN "*.cfl" PATTERN "*.cif")
Simon Ward's avatar
Simon Ward committed
158
159
#
# # Installing tests files
Remi Perenon's avatar
Remi Perenon committed
160
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Tests" DESTINATION ${PYTHON_API_PREFIX} FILES_MATCHING PATTERN "*.py")
Simon Ward's avatar
Simon Ward committed
161
162
163
#
# # Installing documentation files
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html" DESTINATION ${PYTHON_API_PREFIX}/Doc OPTIONAL)