1- cmake_minimum_required (VERSION 3.7 .2 )
1+ cmake_minimum_required (VERSION 3.18 .2 )
22project (psp)
33include (CheckCCompilerFlag )
44
5- set (CMAKE_BUILD_TYPE "Release" )
65set (CMAKE_CXX_STANDARD 14)
76set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
87
@@ -108,12 +107,14 @@ endif()
108107if (NOT DEFINED PSP_PYTHON_BUILD)
109108 set (PSP_PYTHON_BUILD OFF )
110109elseif (PSP_PYTHON_BUILD)
111- # PSP_PYTHON_BUILD will always run PSP_CPP_BUILD
112- set (PSP_CPP_BUILD ON )
113-
114110 if (NOT DEFINED PSP_PYTHON_VERSION)
115111 set (PSP_PYTHON_VERSION 3.10)
116112 endif ()
113+ if ($ENV{PYODIDE} )
114+ set (PSP_PYODIDE 1)
115+ else ()
116+ set (PSP_PYODIDE 0)
117+ endif ()
117118endif ()
118119
119120if (NOT DEFINED PSP_CPP_BUILD_STRICT)
@@ -212,10 +213,10 @@ if(PSP_WASM_BUILD)
212213 list (APPEND CMAKE_PREFIX_PATH /usr/local)
213214
214215 # Assumes that Boost includes will be in this folder.
215- include_directories ("/usr/local/include" SYSTEM )
216+ include_directories (SYSTEM "/usr/local/include" )
216217
217218 # Include this docker-only directory.
218- include_directories ("/boost_includes" )
219+ include_directories (SYSTEM "/boost_includes" )
219220
220221 set (EXTENDED_FLAGS " \
221222 -Wall \
@@ -258,28 +259,45 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
258259 endif ()
259260 else ()
260261 if (CMAKE_BUILD_TYPE_LOWER STREQUAL debug)
261- set (OPT_FLAGS " \
262- -O0 \
263- -g3 \
264- " )
262+ if (PSP_PYODIDE)
263+ set (OPT_FLAGS " \
264+ -O0 \
265+ -g3 \
266+ -gsource-map \
267+ --profiling \
268+ -Wcast-align \
269+ -Wover-aligned \
270+ " )
271+ else ()
272+ set (OPT_FLAGS " \
273+ -O0 \
274+ -g3 \
275+ " )
276+ endif ()
265277 else ()
266278 set (OPT_FLAGS " \
267279 -O3 \
268280 -g1 \
269281 " )
282+ if (PSP_PYODIDE)
283+ set (OPT_FLAGS "${OPT_FLAGS} -flto" )
284+ endif ()
270285 endif ()
271286 endif ()
272287
273288 set (ASYNC_MODE_FLAGS "" )
274289
275290 # Boost is a system dependency and must be present and built on the system.
291+ if (PSP_PYODIDE)
292+ set (CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH} ;/usr/local/" )
293+ endif ()
276294 find_package (Boost REQUIRED )
277295
278296 if (NOT Boost_FOUND)
279297 message (FATAL_ERROR "${Red} Boost could not be located${ColorReset} " )
280298 else ()
281299 psp_build_message ("${Cyan} Found Boost: `Boost_INCLUDE_DIRS`: ${Boost_INCLUDE_DIRS} , `Boost_LIBRARY_DIRS` - ${Boost_LIBRARY_DIRS} ${ColorReset} " )
282- include_directories (${Boost_INCLUDE_DIRS} )
300+ include_directories (SYSTEM ${Boost_INCLUDE_DIRS} )
283301
284302 if (WIN32 )
285303 add_definitions (-DBOOST_UUID_FORCE_AUTO_LINK )
@@ -316,16 +334,13 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
316334 psp_build_message ("${Red} Manylinux build has no python shared libraries${ColorReset} " )
317335 find_package (Python ${PSP_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter )
318336 find_package (PythonHeaders ${PSP_PYTHON_VERSION} EXACT REQUIRED )
319-
320- # Run with exact version so its cached for pybind
321- find_package (PythonInterp ${PSP_PYTHON_VERSION} EXACT REQUIRED )
322337 else ()
323338 psp_build_message ("${Cyan} Use python shared libraries${ColorReset} " )
324- find_package ( Python ${PSP_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development )
325-
326- # Run with exact version so its cached for pybind
327- find_package (PythonInterp ${PSP_PYTHON_VERSION} EXACT REQUIRED )
328- find_package ( PythonLibs ${PSP_PYTHON_VERSION} EXACT REQUIRED )
339+ if (PSP_PYODIDE )
340+ find_package ( Python ${PSP_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter )
341+ else ()
342+ find_package (Python ${PSP_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development.Module )
343+ endif ( )
329344
330345 link_directories (${Python_LIBRARY_DIRS} )
331346 endif ()
@@ -335,7 +350,7 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
335350
336351 psp_build_dep ("pybind11" "${PSP_CMAKE_MODULE_PATH} /Pybind.txt.in" )
337352
338- find_package (NumPy )
353+ find_package (NumPy REQUIRED )
339354
340355 if (NOT PYTHON_NUMPY_FOUND)
341356 message (FATAL_ERROR "${Red} Numpy could not be located${ColorReset} " )
@@ -373,14 +388,18 @@ psp_build_dep("re2" "${PSP_CMAKE_MODULE_PATH}/re2.txt.in")
373388psp_build_dep ("exprtk" "${PSP_CMAKE_MODULE_PATH} /exprtk.txt.in" )
374389
375390# ####################
376- set (CMAKE_C_FLAGS_RELEASE " \
391+ set (CMAKE_C_FLAGS_DEBUG "" )
392+ set (CMAKE_C_FLAGS " \
377393 ${CMAKE_C_FLAGS} \
378394 ${EXTENDED_FLAGS} \
379395 ${OPT_FLAGS} \
380396 " )
381397
382- set (CMAKE_CXX_FLAGS_RELEASE " \
383- ${CMAKE_C_FLAGS} \
398+ # prevents the default debug flags from overriding the debug flags we
399+ # set in OPT_FLAGS
400+ set (CMAKE_CXX_FLAGS_DEBUG "" )
401+ set (CMAKE_CXX_FLAGS " \
402+ ${CMAKE_CXX_FLAGS} \
384403 ${EXTENDED_FLAGS} \
385404 ${OPT_FLAGS} \
386405 " )
@@ -410,6 +429,7 @@ set(SOURCE_FILES
410429 ${PSP_CPP_SRC} /src/cpp/compat.cpp
411430 ${PSP_CPP_SRC} /src/cpp/compat_impl_linux.cpp
412431 ${PSP_CPP_SRC} /src/cpp/compat_impl_osx.cpp
432+ ${PSP_CPP_SRC} /src/cpp/compat_impl_wasm.cpp
413433 ${PSP_CPP_SRC} /src/cpp/compat_impl_win.cpp
414434 ${PSP_CPP_SRC} /src/cpp/computed_expression.cpp
415435 ${PSP_CPP_SRC} /src/cpp/computed_function.cpp
@@ -545,6 +565,27 @@ if(PSP_WASM_BUILD)
545565 set_target_properties (perspective_esm PROPERTIES RUNTIME_OUTPUT_DIRECTORY "./web/" )
546566 set_target_properties (perspective_esm PROPERTIES OUTPUT_NAME "perspective.cpp" )
547567elseif (PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
568+ if (PSP_PYODIDE)
569+ # TODO(tom): this is a straight copy of PSP_WASM_BUILD, merge them
570+ # TODO(tom): determine which of these we shouldn't bother setting
571+ # because pyodide's pywasmcross.py overrides them
572+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
573+ --bind \
574+ --source-map-base \"\" \
575+ --memory-init-file 0 \
576+ --no-entry \
577+ -s EXPORT_ES6=1 \
578+ -s NO_EXIT_RUNTIME=1 \
579+ -s NO_FILESYSTEM=1 \
580+ -s ALLOW_MEMORY_GROWTH=1 \
581+ -s MODULARIZE=1 \
582+ -s EXPORT_NAME=\" load_perspective\" \
583+ -s MAXIMUM_MEMORY=4gb \
584+ -s USE_ES6_IMPORT_META=0 \
585+ -s ERROR_ON_UNDEFINED_SYMBOLS=1 \
586+ -s ENVIRONMENT=web,webview,worker \
587+ " )
588+ endif ()
548589 if (NOT WIN32 )
549590 set (CMAKE_SHARED_LIBRARY_SUFFIX .so)
550591
@@ -569,8 +610,15 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
569610 # #######################
570611 # Python extra targets #
571612 # #######################
572- add_library (psp SHARED ${PYTHON_SOURCE_FILES} )
613+ add_library (psp STATIC ${PYTHON_SOURCE_FILES} )
573614 add_library (binding SHARED ${PYTHON_BINDING_SOURCE_FILES} )
615+ if (PSP_PYODIDE)
616+ set (PSP_PYTHON_DEFS PSP_ENABLE_WASM=1)
617+ else ()
618+ set (PSP_PYTHON_DEFS PSP_ENABLE_PYTHON_THREADING=1)
619+ endif ()
620+ target_compile_definitions (psp PRIVATE ${PSP_PYTHON_DEFS} )
621+ target_compile_definitions (binding PRIVATE ${PSP_PYTHON_DEFS} )
574622
575623 include_directories (${PSP_PYTHON_SRC} /include )
576624
@@ -583,13 +631,16 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
583631
584632 # .dll not importable
585633 set_property (TARGET binding PROPERTY SUFFIX .pyd )
634+ elseif (PSP_PYODIDE)
635+ target_compile_options (psp PRIVATE -fvisibility=hidden )
636+ target_compile_options (binding PRIVATE -fvisibility=hidden )
586637 elseif (MACOS OR NOT MANYLINUX)
587638 target_compile_options (binding PRIVATE -Wdeprecated-declarations )
588639 set_property (TARGET psp PROPERTY INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${module_origin_path} )
589640 set_property (TARGET binding PROPERTY INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${module_origin_path} )
590641
591642 target_compile_options (psp PRIVATE -fvisibility=hidden )
592- target_compile_options (binding PRIVATE -fvisibility=hidden )
643+ target_compile_options (binding PRIVATE -fvisibility=hidden )
593644 else ()
594645 target_compile_options (binding PRIVATE -Wdeprecated-declarations )
595646 endif ()
@@ -612,15 +663,15 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
612663 endif ()
613664
614665 if (PSP_CPP_BUILD_STRICT AND NOT WIN32 )
615- target_compile_options (psp PRIVATE -Wall -Werror )
616- target_compile_options (psp PRIVATE $<$<CONFIG :DEBUG >:-fPIC -O0 >)
666+ # target_compile_options(psp PRIVATE -Wall -Werror)
667+ # target_compile_options(psp PRIVATE $<$<CONFIG:DEBUG>:-fPIC -O0>)
617668
618- if (PSP_PYTHON_BUILD)
669+ if (PSP_PYTHON_BUILD AND NOT PSP_PYODIDE )
619670 target_compile_options (binding PRIVATE $<$<CONFIG :DEBUG >:-fPIC -O0 >)
620671 endif ()
621672 elseif (WIN32 )
622- target_compile_definitions (psp PRIVATE PERSPECTIVE_EXPORTS=1 )
623- target_compile_definitions (psp PRIVATE WIN32 =1 )
624- target_compile_definitions (psp PRIVATE _WIN32=1 )
673+ # target_compile_definitions(psp PRIVATE PERSPECTIVE_EXPORTS=1)
674+ # target_compile_definitions(psp PRIVATE WIN32=1)
675+ # target_compile_definitions(psp PRIVATE _WIN32=1)
625676 endif ()
626677endif ()
0 commit comments