diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 5cd0b05f0d..d67dc4dd7d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -119,10 +119,6 @@ if(MINIMAL_BUILD) set(USD_SUPPORT OFF) endif() -if(NOT BUILD_SHARED_LIBS) - message(FATAL_ERROR "BUILD_SHARED_LIBS=OFF is not supported. Configure with -DBUILD_SHARED_LIBS=ON.") -endif() - if((BUILD_CONVERT OR BUILD_GEOMSERVER OR BUILD_IFCPYTHON) AND(NOT BUILD_IFCGEOM)) message(STATUS "'IfcGeom' is required with current outputs") set(BUILD_IFCGEOM ON) diff --git a/nix/build-all.py b/nix/build-all.py index 2fa2626e6e..79b0a64932 100644 --- a/nix/build-all.py +++ b/nix/build-all.py @@ -591,6 +591,10 @@ def run_cmake(arg1, cmake_args: "list[str]", cmake_dir: Union[str, None] = None, f"-DBUILD_SHARED_LIBS={OFF_ON[not BUILD_STATIC]}", ) + module_flags = [] + if "wasm" in flags: + module_flags.append(f"-DCMAKE_MODULE_LINKER_FLAGS={os.environ['LDFLAGS']}") + run( [ *wasm, @@ -600,6 +604,7 @@ def run_cmake(arg1, cmake_args: "list[str]", cmake_dir: Union[str, None] = None, *cmake_args, f"-DCMAKE_BUILD_TYPE={BUILD_CFG}", f"-DCMAKE_SHARED_LINKER_FLAGS={os.environ['LDFLAGS']}", + *module_flags ], cwd=cwd, ) @@ -1341,7 +1346,7 @@ os.makedirs(ifcos_build_dir, exist_ok=True) cmake_args = [ "-DUSE_MMAP=OFF", "-DBUILD_EXAMPLES=OFF", - "-DBUILD_SHARED_LIBS=ON", + "-DBUILD_SHARED_LIBS=" + OFF_ON[not BUILD_STATIC], "-DGLTF_SUPPORT=ON", "-DBoost_NO_BOOST_CMAKE=On", "-DCREATE_BUNDLE=On", @@ -1394,9 +1399,9 @@ elif "occ" in targets: occ_library_dir = f"{DEPS_DIR}/install/oce-{OCE_VERSION}/lib" cmake_args.extend(["-DOCC_INCLUDE_DIR=" + occ_include_dir, "-DOCC_LIBRARY_DIR=" + occ_library_dir]) -if "manifold" in targets: - cmake_args_prefix_path.append(f"{DEPS_DIR}/install/manifold-{MANIFOLD_VERSION}") - cmake_args.append("-DWITH_MANIFOLD=On") +# if "manifold" in targets: +# cmake_args_prefix_path.append(f"{DEPS_DIR}/install/manifold-{MANIFOLD_VERSION}") +# cmake_args.append("-DWITH_MANIFOLD=On") if "OpenCOLLADA" in targets: # pcre is a dependency of OpenCOLLADA, but since we `find_package`, diff --git a/pyodide/meta.yaml b/pyodide/meta.yaml index 7c6580d801..fd8e6b4102 100644 --- a/pyodide/meta.yaml +++ b/pyodide/meta.yaml @@ -8,7 +8,7 @@ source: build: script: | - BUILD_CFG=Release python nix/build-all.py -v --wasm --py313 + CFLAGS="-O0 -g" CXXFLAGS="-O0 -g" LDFLAGS="-O0 -g" IFCOS_SCHEMAS=4 BUILD_CFG=Debug python nix/build-all.py -v --wasm --py313 about: home: http://ifcopenshell.org diff --git a/src/ifcgeom/Serialization/schema/CMakeLists.txt b/src/ifcgeom/Serialization/schema/CMakeLists.txt index 5d56ebf383..c9e77debe6 100644 --- a/src/ifcgeom/Serialization/schema/CMakeLists.txt +++ b/src/ifcgeom/Serialization/schema/CMakeLists.txt @@ -1,3 +1,5 @@ +if (NOT WASM_BUILD) + foreach(schema ${SCHEMA_VERSIONS}) add_library(geometry_serializer_ifc${schema} SHARED Serialization.cpp plugin.cpp) target_link_libraries(geometry_serializer_ifc${schema} PRIVATE plugin geometry_serializer IfcGeom IfcParse ${OpenCASCADE_LIBRARIES}) @@ -10,3 +12,5 @@ foreach(schema ${SCHEMA_VERSIONS}) list(APPEND geometry_serializer_libraries geometry_serializer_ifc${schema}) endforeach() set(geometry_serializer_libraries ${geometry_serializer_libraries} PARENT_SCOPE) + +endif() diff --git a/src/ifcgeom/kernels/CMakeLists.txt b/src/ifcgeom/kernels/CMakeLists.txt index af5b415ef9..7794bd05f7 100644 --- a/src/ifcgeom/kernels/CMakeLists.txt +++ b/src/ifcgeom/kernels/CMakeLists.txt @@ -2,6 +2,12 @@ message(STATUS "GEOMETRY_KERNELS ${GEOMETRY_KERNELS}") set(kernel_plugin_runtime_dir "${CMAKE_BINARY_DIR}/ifcgeom/$") +if (NOT WASM_BUILD) +# wasm-ld (?) trips up on multiple defined symbols. IfcParse already brings +# in plugin so we skip it here. +set(plugin_when_not_wasm plugin) +endif() + foreach(kernel ${GEOMETRY_KERNELS}) string(TOUPPER ${kernel} KERNEL_UPPER) file(GLOB IFCGEOM_H_FILES ${kernel}/*.h) @@ -16,6 +22,14 @@ foreach(kernel ${GEOMETRY_KERNELS}) set(KERNEL_TARGET "geometry_kernel_${kernel}") add_library(${KERNEL_TARGET} SHARED ${IFCGEOM_FILES}) + + if (WASM_BUILD) + target_link_options( + ${KERNEL_TARGET} + PRIVATE "SHELL:-s -s SIDE_MODULE=1" + ) + endif() + set_target_properties(${KERNEL_TARGET} PROPERTIES COMPILE_FLAGS "-DIFC_GEOMLIBRARY_EXPORTS" OUTPUT_NAME "geometry.kernel.${kernel}" @@ -23,7 +37,7 @@ foreach(kernel ${GEOMETRY_KERNELS}) LIBRARY_OUTPUT_DIRECTORY "${kernel_plugin_runtime_dir}" ) list(APPEND kernel_libraries ${KERNEL_TARGET}) - target_link_libraries(${KERNEL_TARGET} PRIVATE plugin IfcGeom ${${KERNEL_UPPER}_LIBRARIES} Eigen3::Eigen) + target_link_libraries(${KERNEL_TARGET} PRIVATE ${plugin_when_not_wasm} IfcGeom ${${KERNEL_UPPER}_LIBRARIES} Eigen3::Eigen) install(TARGETS ${KERNEL_TARGET}) @@ -32,6 +46,14 @@ foreach(kernel ${GEOMETRY_KERNELS}) set(KERNEL_TARGET_SIMPLE "${KERNEL_TARGET}_simple") add_library(${KERNEL_TARGET_SIMPLE} SHARED ${IFCGEOM_FILES}) + + if (WASM_BUILD) + target_link_options( + ${KERNEL_TARGET_SIMPLE} + PRIVATE "SHELL:-s -s SIDE_MODULE=1" + ) + endif() + set_target_properties(${KERNEL_TARGET_SIMPLE} PROPERTIES COMPILE_FLAGS "-DIFC_GEOMLIBRARY_EXPORTS -DIFOPSH_SIMPLE_KERNEL -DCGAL_HAS_THREADS" OUTPUT_NAME "geometry.kernel.cgalsimple" @@ -39,11 +61,20 @@ foreach(kernel ${GEOMETRY_KERNELS}) LIBRARY_OUTPUT_DIRECTORY "${kernel_plugin_runtime_dir}" ) list(APPEND kernel_libraries ${KERNEL_TARGET_SIMPLE}) - target_link_libraries(${KERNEL_TARGET_SIMPLE} PRIVATE plugin IfcGeom ${${KERNEL_UPPER}_LIBRARIES} Eigen3::Eigen) + target_link_libraries(${KERNEL_TARGET_SIMPLE} PRIVATE ${plugin_when_not_wasm} IfcGeom ${${KERNEL_UPPER}_LIBRARIES} Eigen3::Eigen) install(TARGETS ${KERNEL_TARGET_SIMPLE}) elseif(${kernel} STREQUAL "opencascade") - target_link_libraries(${KERNEL_TARGET} PRIVATE ${OpenCASCADE_LIBRARIES}) + if (WASM_BUILD) + # exclude due to duplicate symbols tripping up wasm-ld + set(OCCT_LIBS_FILTERED ${OpenCASCADE_LIBRARIES}) + list(FILTER OCCT_LIBS_FILTERED EXCLUDE REGEX "(^|;)TKXMesh($|;)") + target_link_libraries(${KERNEL_TARGET} PRIVATE ${OCCT_LIBS_FILTERED}) + # message(FATAL_ERROR "OCCT_LIBS_FILTERED ${OCCT_LIBS_FILTERED}") + else() + target_link_libraries(${KERNEL_TARGET} PRIVATE ${OpenCASCADE_LIBRARIES}) + endif() + if (NOT WASM_BUILD) foreach(tree_backend brep trianglebvh) set(TREE_TARGET "geometry_tree_opencascade_${tree_backend}") add_library(${TREE_TARGET} SHARED @@ -60,6 +91,7 @@ foreach(kernel ${GEOMETRY_KERNELS}) target_link_libraries(${TREE_TARGET} PRIVATE plugin IfcGeom geometry_kernel_opencascade ${OpenCASCADE_LIBRARIES} Eigen3::Eigen) install(TARGETS ${TREE_TARGET}) endforeach() + endif() endif() install(FILES ${IFCGEOM_H_FILES} diff --git a/src/ifcgeom/mapping/CMakeLists.txt b/src/ifcgeom/mapping/CMakeLists.txt index 77778df425..b218453248 100644 --- a/src/ifcgeom/mapping/CMakeLists.txt +++ b/src/ifcgeom/mapping/CMakeLists.txt @@ -2,6 +2,12 @@ find_package(Eigen3 REQUIRED) set(mapping_plugin_runtime_dir "${CMAKE_BINARY_DIR}/ifcgeom/$") +if (NOT WASM_BUILD) +# wasm-ld (?) trips up on multiple defined symbols. IfcParse already brings +# in plugin so we skip it here. +set(plugin_when_not_wasm plugin) +endif() + foreach(schema ${SCHEMA_VERSIONS}) file(GLOB IFCGEOM_I_FILES *.i) file(GLOB IFCGEOM_H_FILES *.h) @@ -15,7 +21,15 @@ foreach(schema ${SCHEMA_VERSIONS}) RUNTIME_OUTPUT_DIRECTORY "${mapping_plugin_runtime_dir}" LIBRARY_OUTPUT_DIRECTORY "${mapping_plugin_runtime_dir}" ) - target_link_libraries(geometry_mapping_ifc${schema} PRIVATE plugin IfcGeom IfcParse Eigen3::Eigen ${OpenCASCADE_LIBRARIES}) + + if (WASM_BUILD) + target_link_options( + geometry_mapping_ifc${schema} + PRIVATE "SHELL:-s -s SIDE_MODULE=1" + ) + endif() + + target_link_libraries(geometry_mapping_ifc${schema} PRIVATE ${plugin_when_not_wasm} IfcGeom IfcParse Eigen3::Eigen) list(APPEND mapping_libraries geometry_mapping_ifc${schema}) diff --git a/src/ifcparse/character_decoder.cpp b/src/ifcparse/character_decoder.cpp index b354c70052..89b96156cc 100644 --- a/src/ifcparse/character_decoder.cpp +++ b/src/ifcparse/character_decoder.cpp @@ -311,11 +311,11 @@ std::string character_decoder::get(size_t& ptr) { return s; } -template class IFC_PARSE_API character_decoder>; -template class IFC_PARSE_API character_decoder>; -template class IFC_PARSE_API character_decoder>; +template class IFC_PARSE_API ifcopenshell::character_decoder>; +template class IFC_PARSE_API ifcopenshell::character_decoder>; +template class IFC_PARSE_API ifcopenshell::character_decoder>; #ifdef USE_MMAP -template class IFC_PARSE_API character_decoder>; +template class IFC_PARSE_API ifcopenshell::character_decoder>; #endif character_encoder::character_encoder(const std::string& input) diff --git a/src/ifcparse/file.h b/src/ifcparse/file.h index f0f74583ad..f4a900b5f8 100644 --- a/src/ifcparse/file.h +++ b/src/ifcparse/file.h @@ -412,16 +412,6 @@ public: void build_inverses_(const express::Base& entity); - // @nb this does not support id assignment - template - T create(Ts&&... args) { - T t = create(&T::Class()).template as(); - if constexpr (sizeof...(Ts) > 0) { - t.initialize(std::forward(args)...); - } - return t; - } - template T create(int instance_id = -1) { return create(&T::Class(), instance_id).template as(); diff --git a/src/ifcparse/parse.cpp b/src/ifcparse/parse.cpp index f1a1ba2fd6..14ebb1a1b4 100644 --- a/src/ifcparse/parse.cpp +++ b/src/ifcparse/parse.cpp @@ -411,11 +411,11 @@ token spf_lexer::next() { } } -template class IFC_PARSE_API spf_lexer>; -template class IFC_PARSE_API spf_lexer>; -template class IFC_PARSE_API spf_lexer>; +template class IFC_PARSE_API ifcopenshell::spf_lexer>; +template class IFC_PARSE_API ifcopenshell::spf_lexer>; +template class IFC_PARSE_API ifcopenshell::spf_lexer>; #ifdef USE_MMAP -template class IFC_PARSE_API spf_lexer>; +template class IFC_PARSE_API ifcopenshell::spf_lexer>; #endif bool token::is_operator() { diff --git a/src/serializers/CMakeLists.txt b/src/serializers/CMakeLists.txt index 7e86046a9c..093a931094 100644 --- a/src/serializers/CMakeLists.txt +++ b/src/serializers/CMakeLists.txt @@ -4,12 +4,18 @@ set(geometry_serializer_plugin_runtime_dir "${CMAKE_BINARY_DIR}/serializers/$