File: CMakeLists.txt

package info (click to toggle)
ecflow 5.15.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,868 kB
  • sloc: cpp: 269,341; python: 22,756; sh: 3,609; perl: 770; xml: 333; f90: 204; ansic: 141; makefile: 70
file content (186 lines) | stat: -rw-r--r-- 6,008 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#
# Copyright 2009- ECMWF.
#
# This software is licensed under the terms of the Apache Licence version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#

#
#   Important!
#
# Notice that ecflow Python module is linked with `Python3::Module` CMake imported target,
# to enable a loose linkage with Python development libraries -- this is necessary in some
# platforms, such as conda-forge+macOS.
#
# In practice, this implies that `-undefined` and `-dynamic_lookup` linkage flags are used
# and the Python development libraries are not linked directly into the ecflow Python module.
#

ecbuild_add_library(
  TARGET
    ecflow3
  NOINSTALL
  TYPE MODULE
  SOURCES
    ${srcs}
  PRIVATE_INCLUDES
    ../src
  PUBLIC_LIBS
    ecflow_all
    libsimulator
    Python3::Module
    Boost::${ECFLOW_BOOST_PYTHON_COMPONENT}
    $<$<BOOL:${OPENSSL_FOUND}>:OpenSSL::SSL>
  CXXFLAGS
    $<$<CXX_COMPILER_ID:Clang>:-Wno-macro-redefined>
)

target_clangformat(ecflow3)

#
# Override default behaviour that add RPATHS during install
# The only thing that seem to work is set INSTALL_RPATH to ""
# Using SKIP_BUILD_RPATH,BUILD_WITH_INSTALL_RPATH,INSTALL_RPATH_USE_LINK_PATH
# had no effect
#         
# by default cmake add prefix 'lib', we don't want this hence disable
#
# To avoid duplicate target names we chose to name the targets: ecflow2/ecflow3.
# however test and user code  depend on name 'ecflow', hence we rename the output to 'cflow'
set_target_properties(ecflow3
  PROPERTIES
    OUTPUT_NAME "ecflow"
    PREFIX ""
    INSTALL_RPATH ""
)

# =====================================================================
# tests

foreach( test ${u_tests} )
  ecbuild_add_test(
    TARGET
      py3_${test}
    LABELS
      python nightly
    TYPE PYTHON
    ARGS
      ${CMAKE_CURRENT_SOURCE_DIR}/../test/py_${test}.py
    ENVIRONMENT
      "PATH=${Python3_EXECUTABLE_DIR}:$ENV{PATH};PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}"
    TEST_DEPENDS
      u_base
  )
endforeach()


if ( ENABLE_ALL_TESTS AND ENABLE_SERVER)

  foreach( test ${s_tests} )
    ecbuild_add_test(
      TARGET
        py3_${test}
      LABELS
        python nightly
      TYPE PYTHON
      ARGS
        ${CMAKE_CURRENT_SOURCE_DIR}/../test/py_${test}.py
      ENVIRONMENT
        "PATH=${Python3_EXECUTABLE_DIR}:$ENV{PATH};PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR};ECF_SSL_DIR=${CMAKE_CURRENT_BINARY_DIR}/"
      TEST_DEPENDS
        u_base
    )
  endforeach()
  
  set_property(TEST py3_s_TestClientApi      APPEND PROPERTY DEPENDS s_test)
  set_property(TEST py3_s_TestPythonChildApi APPEND PROPERTY DEPENDS py3_s_TestClientApi)
endif()


# ==========================================================================
# install
#    -DCMAKE_PYTHON_INSTALL_TYPE = [ local | setup | not defined ]
#
#    local | not defined : this will install to:
#                          $INSTALL_PREFIX/$release.$major.$minor/lib/python2.7/site-packages/ecflow/
#    setup               : experimental only,python way of installing
#
#    -DCMAKE_PYTHON_INSTALL_PREFIX should *only* used when using python setup.py (CMAKE_PYTHON_INSTALL_TYPE=setup)
#    *AND* for testing python install to local directory
#
# Note:  To install only the python module
#       cd  buildir
#       cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCOMPONENT=python -P cmake_install.cmake -- make install
# ==========================================================================

if( CMAKE_PYTHON_INSTALL_TYPE MATCHES  "local"  OR NOT DEFINED CMAKE_PYTHON_INSTALL_TYPE )

  if( NOT INSTALL_PYTHON3_DIR )
    set(PYTHON_SITE "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages" )
  else()
    # Resolve ${VAR} in the value provided
    string(CONFIGURE "${INSTALL_PYTHON3_DIR}" PYTHON_SITE)
  endif()
  set(PYTHON_DEST "${PYTHON_SITE}/ecflow" )

  install(
    TARGETS
      ecflow3
    DESTINATION
      ${PYTHON_DEST}
    RENAME
      ecflow.so
    COMPONENT
      python
  )
  install(
    FILES
      ../ecflow/__init__.py
      ../samples/api/ecf.py
      ../samples/api/sms2ecf.py
    DESTINATION
      ${PYTHON_DEST}
    COMPONENT
      python
  )

else()

  message( STATUS "python found,  CMAKE_PYTHON_INSTALL_TYPE=${CMAKE_PYTHON_INSTALL_TYPE}")

  # -------------------------------------------------------------------------------------
  # Install using setup.py
  # See: http://bloerg.net/2012/11/10/cmake-and-distutils.html
  # -------------------------------------------------------------------------------------
  message(STATUS "python install using *setup.py* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
  message(STATUS "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}")
  message(STATUS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
  message(STATUS "CMAKE_PYTHON_INSTALL_PREFIX : ${CMAKE_PYTHON_INSTALL_PREFIX}" )

  set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py.in")
  set(SETUP_PY    "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py")
  set(DEPS        "${CMAKE_CURRENT_SOURCE_DIR}/../ecflow/__init__.py")
  set(OUTPUT      "${CMAKE_CURRENT_SOURCE_DIR}/timestamp")

  configure_file(${SETUP_PY_IN} ${SETUP_PY} )

  add_custom_command(
    OUTPUT ${OUTPUT}
    COMMAND ${PYTHON} ${SETUP_PY} build
    COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
    DEPENDS ${DEPS}
  )
  add_custom_target(target ALL DEPENDS ${OUTPUT})

  install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} build_ext)")

  if( DEFINED CMAKE_PYTHON_INSTALL_PREFIX )
    message(STATUS "custom/*test* python install prefix defined CMAKE_PYTHON_INSTALL_PREFIX=${CMAKE_PYTHON_INSTALL_PREFIX}")
    install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install -f --prefix=${CMAKE_PYTHON_INSTALL_PREFIX})")
  else()
    install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install)")
  endif()
endif()