@@ -9,20 +9,21 @@ else ()
9
9
endif ()
10
10
11
11
if (APPLE )
12
- set (CMAKE_POSITION_INDEPENDENT_CODE False )
12
+ set (CMAKE_POSITION_INDEPENDENT_CODE FALSE )
13
13
else ()
14
- set (CMAKE_POSITION_INDEPENDENT_CODE True )
14
+ set (CMAKE_POSITION_INDEPENDENT_CODE TRUE )
15
15
endif ()
16
16
17
17
project (xmsinterp C CXX)
18
18
19
19
include (GNUInstallDirs)
20
+ include (GenerateExportHeader)
20
21
21
22
set (BUILD_SHARED_LIBS OFF CACHE BOOL "Enable/Disable building shared libraries" )
22
23
set (BUILD_TESTING NO CACHE BOOL "Enable/Disable testing" )
23
24
set (XMS_BUILD_MODE "CONAN" CACHE STRING "Target packing system to build for." )
24
25
set_property (CACHE XMS_BUILD_MODE PROPERTY STRINGS "CONAN;CONDA;CMAKE" )
25
- set (XMS_BUILD NO CACHE BOOL "Set this if you want to use this package with XMS." )
26
+ set (XMS_BUILD ON CACHE BOOL "Set this if you want to use this package with XMS." )
26
27
set (CONDA_PREFIX "" CACHE PATH "Path to the conda environment used to build." )
27
28
set (ENABLE_PYTHON OFF CACHE BOOL "Set this if you want to build the python bindings." )
28
29
set (PYTHON_TARGET_VERSION 3.6 CACHE STRING "Version of python to link to for python wrapping." )
@@ -31,26 +32,42 @@ set(XMS_VERSION "5.2.0" CACHE STRING "Library Version")
31
32
32
33
add_definitions (-DXMS_VERSION=\"${XMS_VERSION} \")
33
34
35
+ # Do this because it doesn't work otherwise...
36
+ if (BUILD_SHARED_LIBS AND WIN32 )
37
+ set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
38
+ endif ()
39
+
34
40
if (ENABLE_PYTHON AND BUILD_TESTING)
35
41
message (FATAL_ERROR "Cannot build python module when testing is enabled" )
36
42
endif ()
37
43
38
44
if (XMS_BUILD_MODE STREQUAL "CONDA" )
39
45
include (${CMAKE_CURRENT_LIST_DIR} /condabuildinfo.cmake)
40
46
elseif (XMS_BUILD_MODE STREQUAL "CMAKE" )
47
+ if (PYTHON_TARGET_VERSION VERSION_LESS 3)
48
+ message (FATAL_ERROR "XMS requires Python >= 3.0" )
49
+ endif ()
41
50
if (BUILD_SHARED_LIBS )
42
51
set (Boost_USE_STATIC_LIBS OFF )
43
52
else ()
44
53
set (Boost_USE_STATIC_LIBS ON )
45
54
endif ()
55
+ find_package (ZLIB QUIET REQUIRED)
46
56
find_package (Boost QUIET REQUIRED log_setup log system filesystem serialization timer)
47
57
find_package (XMSCore QUIET REQUIRED
48
58
NAMES xms xmscore)
49
59
find_package (XMSGrid QUIET REQUIRED
50
60
NAMES xms xmsgrid)
51
- list (APPEND EXT_INCLUDE_DIRS ${XMSCore_INCLUDE_DIRS} ;${XMSGrid_INCLUDE_DIRS} ;${Boost_INCLUDE_DIRS} )
61
+ list (APPEND EXT_INCLUDE_DIRS ${XMSCore_INCLUDE_DIRS} ;${XMSGrid_INCLUDE_DIRS} ;${Boost_INCLUDE_DIRS} ; ${ZLIB_INCLUDE_DIRS} )
52
62
list (APPEND EXT_LIB_DIRS ${XMSCore_LIBRARY_DIRS} ;${XMSGrid_LIBRARY_DIRS} ;${Boost_LIBRARY_DIRS} )
53
- list (APPEND EXT_LIBS ${XMSCore_LIBRARIES} ;${XMSGrid_LIBRARIES} ;${Boost_LIBRARIES} ;z)
63
+ list (APPEND EXT_LIBS ${XMSCore_LIBRARIES} ;${XMSGrid_LIBRARIES} ;${Boost_LIBRARIES} ;${ZLIB_LIBRARIES} )
64
+ if (WIN32 )
65
+ if (XMS_BUILD)
66
+ add_definitions (/Zc:wchar_t) # Treat wchar_t as built-in type
67
+ add_definitions (/D _WIN32_WINNT=0x0501) # Windows XP and higher
68
+ endif ()
69
+ add_definitions (/D BOOST_ALL_NO_LIB)
70
+ endif ()
54
71
else () # If we are not using conda, we are using conan
55
72
# Conan setup
56
73
include (${CMAKE_BINARY_DIR} /conanbuildinfo.cmake)
@@ -60,7 +77,7 @@ else () # If we are not using conda, we are using conan
60
77
list (APPEND EXT_LIBS ${CONAN_LIBS} )
61
78
endif ()
62
79
63
- if (WIN32 )
80
+ if (WIN32 AND XMS_BUILD_MODE STREQUAL "CONAN" )
64
81
string (COMPARE EQUAL "${CONAN_SETTINGS_COMPILER_RUNTIME} " "MT" USES_MT)
65
82
if (NOT USES_MT)
66
83
string (COMPARE EQUAL "${CONAN_SETTINGS_COMPILER_RUNTIME} " "MTd" USES_MT)
@@ -100,23 +117,22 @@ if (ENABLE_PYTHON)
100
117
endif ()
101
118
102
119
find_package (PythonLibsNew ${PYTHON_TARGET_VERSION} EXACT REQUIRED)
120
+ list (APPEND EXT_INCLUDE_DIRS
121
+ ${pybind11_INCLUDE_DIR}
122
+ )
123
+
124
+ message ("PYTHON_INCLUDE: ${PYTHON_INCLUDE_DIRS} " )
125
+ message ("PYTHON_LIBS: ${PYTHON_LIBRARIES} " )
126
+
127
+ list (APPEND EXT_INCLUDE_DIRS
128
+ ${PYTHON_INCLUDE_DIRS}
129
+ )
103
130
else ()
104
131
# New method does not require PythonLibsNew
105
- find_package (Python REQUIRED COMPONENTS Interpreter)
106
- set (PYTHON_EXECUTABLE ${Python_EXECUTABLE} )
132
+ find_package (Python3 REQUIRED COMPONENTS Interpreter Development)
107
133
find_package (pybind11 CONFIG REQUIRED)
134
+ list (APPEND EXT_LIBS pybind11::pybind11 Python3::Python)
108
135
endif ()
109
-
110
- list (APPEND EXT_INCLUDE_DIRS
111
- ${pybind11_INCLUDE_DIR}
112
- )
113
-
114
- message ("PYTHON_INCLUDE: ${PYTHON_INCLUDE_DIRS} " )
115
- message ("PYTHON_LIBS: ${PYTHON_LIBRARIES} " )
116
-
117
- list (APPEND EXT_INCLUDE_DIRS
118
- ${PYTHON_INCLUDE_DIRS}
119
- )
120
136
endif ()
121
137
122
138
include_directories (${CMAKE_CURRENT_LIST_DIR} )
@@ -223,14 +239,22 @@ target_link_libraries(${PROJECT_NAME}
223
239
if (UNIX AND NOT APPLE )
224
240
target_link_libraries (${PROJECT_NAME} rt)
225
241
endif ()
242
+ generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME xmsinterp/xmsinterp_export.h)
243
+ target_include_directories (xmsinterp
244
+ PUBLIC
245
+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR} >
246
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >)
247
+ install (FILES ${PROJECT_BINARY_DIR} /xmsinterp/xmsinterp_export.h
248
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /xmsinterp
249
+ )
226
250
227
251
if (ENABLE_PYTHON)
228
252
pybind11_add_module(_xmsinterp
229
253
${xmsinterp_py} ${xmsinterp_py_headers}
230
254
)
231
255
target_include_directories (_xmsinterp
232
256
PRIVATE
233
- ${EXT_LIBS}
257
+ ${EXT_LIBS}
234
258
${PYTHON_INCLUDE_DIRS}
235
259
)
236
260
target_link_libraries (_xmsinterp
@@ -241,6 +265,16 @@ if (ENABLE_PYTHON)
241
265
set_target_properties (_xmsinterp PROPERTIES
242
266
LINKER_LANGUAGE CXX
243
267
)
268
+ generate_export_header(_xmsinterp
269
+ BASE_NAME xmsinterppy
270
+ EXPORT_FILE_NAME xmsinterp/python/xmsinterppy_export.h)
271
+ target_include_directories (_xmsinterp
272
+ PUBLIC
273
+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR} >
274
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >)
275
+ install (FILES ${PROJECT_BINARY_DIR} /xmsinterp/python/xmsinterppy_export.h
276
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} xmsinterp/python
277
+ )
244
278
245
279
if (XMS_BUILD_MODE STREQUAL "CMAKE" )
246
280
# Using a standard installation heirarchy for python packages
0 commit comments