diff --git a/CMakeLists.txt b/CMakeLists.txt index aa6a6a64..e159edcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,10 +99,34 @@ if (NOT TARGET xeus AND NOT TARGET xeus-static) endif() endif () -find_package(CppInterOp ${CppInterOp_REQUIRED_VERSION} REQUIRED) -if(CppInterOp_FOUND) - message(STATUS "Found CppInterOp: config=${CPPINTEROP_CMAKE_DIR} dir=${CPPINTEROP_INSTALL_PREFIX} (found version=${CPPINTEROP_VERSION} compatible with Clang ${CPPINTEROP_LLVM_VERSION_MAJOR}.x)") -endif() +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + find_package(CppInterOp ${CppInterOp_REQUIRED_VERSION} REQUIRED) + if(CppInterOp_FOUND) + message(STATUS "Found CppInterOp: config=${CPPINTEROP_CMAKE_DIR} dir=${CPPINTEROP_INSTALL_PREFIX} (found version=${CPPINTEROP_VERSION} compatible with Clang ${CPPINTEROP_LLVM_VERSION_MAJOR}.x)") + endif() + if(EMSCRIPTEN) + set(XEUS_CPP_CPPINTEROP_SHARED_JSON "") + if (CPPINTEROP_SHARED_LIB) + set(XEUS_CPP_CPPINTEROP_SHARED_JSON + ",\n \"libclangCppInterOp.so\": \"lib/libclangCppInterOp.so\"") + endif () + endif () + set(XEUS_CPP_TEST_BINARY_DIRECTORY "${CMAKE_BINARY_DIR}/test/") +else () + set(XEUS_CPP_TEST_BINARY_DIRECTORY "${CMAKE_BINARY_DIR}/bin/") + get_target_property( + CPPINTEROP_LIBRARY_TYPE + clangCppInterOp + TYPE + ) + + if(CPPINTEROP_LIBRARY_TYPE STREQUAL "SHARED_LIBRARY") + set(CPPINTEROP_SHARED_LIB TRUE) + set(CPPINTEROP_LIBRARIES "${CMAKE_BINARY_DIR}/lib/libclangCppInterOp.so.${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}") + set(XEUS_CPP_CPPINTEROP_SHARED_JSON + ",\n \"libclangCppInterOp.so\": \"lib/libclangCppInterOp.so\"") + endif () +endif () find_package(argparse REQUIRED) find_package(pugixml REQUIRED) diff --git a/share/jupyter/kernels/xc11/wasm_kernel.json.in b/share/jupyter/kernels/xc11/wasm_kernel.json.in index a74ad4ba..db662fac 100644 --- a/share/jupyter/kernels/xc11/wasm_kernel.json.in +++ b/share/jupyter/kernels/xc11/wasm_kernel.json.in @@ -13,8 +13,8 @@ "metadata": { "debugger": false, "shared": { - "libxeus.so": "lib/libxeus.so", - "libclangCppInterOp.so": "lib/libclangCppInterOp.so" + "libxeus.so": "lib/libxeus.so" + @XEUS_CPP_CPPINTEROP_SHARED_JSON@ } } } diff --git a/share/jupyter/kernels/xc17/wasm_kernel.json.in b/share/jupyter/kernels/xc17/wasm_kernel.json.in index a820d69b..4315a427 100644 --- a/share/jupyter/kernels/xc17/wasm_kernel.json.in +++ b/share/jupyter/kernels/xc17/wasm_kernel.json.in @@ -13,8 +13,8 @@ "metadata": { "debugger": false, "shared": { - "libxeus.so": "lib/libxeus.so", - "libclangCppInterOp.so": "lib/libclangCppInterOp.so" + "libxeus.so": "lib/libxeus.so" + @XEUS_CPP_CPPINTEROP_SHARED_JSON@ } } } diff --git a/share/jupyter/kernels/xc23/wasm_kernel.json.in b/share/jupyter/kernels/xc23/wasm_kernel.json.in index 7dd2bd3c..8d00e7b0 100644 --- a/share/jupyter/kernels/xc23/wasm_kernel.json.in +++ b/share/jupyter/kernels/xc23/wasm_kernel.json.in @@ -13,8 +13,8 @@ "metadata": { "debugger": false, "shared": { - "libxeus.so": "lib/libxeus.so", - "libclangCppInterOp.so": "lib/libclangCppInterOp.so" + "libxeus.so": "lib/libxeus.so" + @XEUS_CPP_CPPINTEROP_SHARED_JSON@ } } } diff --git a/share/jupyter/kernels/xcpp17/wasm_kernel.json.in b/share/jupyter/kernels/xcpp17/wasm_kernel.json.in index 02ec0595..88aacb22 100644 --- a/share/jupyter/kernels/xcpp17/wasm_kernel.json.in +++ b/share/jupyter/kernels/xcpp17/wasm_kernel.json.in @@ -12,8 +12,8 @@ "metadata": { "debugger": false, "shared": { - "libxeus.so": "lib/libxeus.so", - "libclangCppInterOp.so": "lib/libclangCppInterOp.so" + "libxeus.so": "lib/libxeus.so" + @XEUS_CPP_CPPINTEROP_SHARED_JSON@ } } } diff --git a/share/jupyter/kernels/xcpp20/wasm_kernel.json.in b/share/jupyter/kernels/xcpp20/wasm_kernel.json.in index 015bd5a3..148fd971 100644 --- a/share/jupyter/kernels/xcpp20/wasm_kernel.json.in +++ b/share/jupyter/kernels/xcpp20/wasm_kernel.json.in @@ -12,8 +12,8 @@ "metadata": { "debugger": false, "shared": { - "libxeus.so": "lib/libxeus.so", - "libclangCppInterOp.so": "lib/libclangCppInterOp.so" + "libxeus.so": "lib/libxeus.so" + @XEUS_CPP_CPPINTEROP_SHARED_JSON@ } } } diff --git a/share/jupyter/kernels/xcpp23/wasm_kernel.json.in b/share/jupyter/kernels/xcpp23/wasm_kernel.json.in index 2de544f6..c1291759 100644 --- a/share/jupyter/kernels/xcpp23/wasm_kernel.json.in +++ b/share/jupyter/kernels/xcpp23/wasm_kernel.json.in @@ -12,8 +12,8 @@ "metadata": { "debugger": false, "shared": { - "libxeus.so": "lib/libxeus.so", - "libclangCppInterOp.so": "lib/libclangCppInterOp.so" + "libxeus.so": "lib/libxeus.so" + @XEUS_CPP_CPPINTEROP_SHARED_JSON@ } } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7ccf116e..0f2cbcce 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -77,22 +77,22 @@ if(EMSCRIPTEN) ) target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR}) - - add_custom_command(TARGET test_xeus_cpp POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_INSTALL_PREFIX}/lib/libclangCppInterOp.so - ${CMAKE_CURRENT_BINARY_DIR}/libclangCppInterOp.so - COMMENT "Copying libclangCppInterOp.so to the test directory" - ) - + if (CPPINTEROP_SHARED_LIB) + add_custom_command(TARGET test_xeus_cpp POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CPPINTEROP_LIBRARIES} + ${XEUS_CPP_TEST_BINARY_DIRECTORY}/libclangCppInterOp.so + COMMENT "Copying libclangCppInterOp.so to the test directory" + ) + endif () add_custom_command(TARGET test_xeus_cpp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_INSTALL_PREFIX}/lib/libxeus.so - ${CMAKE_CURRENT_BINARY_DIR}/libxeus.so + ${XEUS_CPP_TEST_BINARY_DIRECTORY}/libxeus.so COMMENT "Copying libxeus.so to the test directory" ) add_custom_target(check-xeus-cpp - COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} node test_xeus_cpp.js + COMMAND ${CMAKE_COMMAND} -E chdir ${XEUS_CPP_TEST_BINARY_DIRECTORY} node test_xeus_cpp.js DEPENDS test_xeus_cpp ) else()