diff --git a/lib/CppInterOp/CMakeLists.txt b/lib/CppInterOp/CMakeLists.txt index 41288fb60..5f5cbf1d1 100644 --- a/lib/CppInterOp/CMakeLists.txt +++ b/lib/CppInterOp/CMakeLists.txt @@ -18,25 +18,22 @@ else() list(APPEND LLVM_LINK_COMPONENTS OrcDebugging) endif() endif() - set(DLM - DynamicLibraryManager.cpp - DynamicLibraryManagerSymbol.cpp - Paths.cpp - ) - if (CPPINTEROP_USE_CLING) - set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${DLM}) - set(DLM) - endif(CPPINTEROP_USE_CLING) - if (CPPINTEROP_USE_REPL) - #Use DML optional sources - endif(CPPINTEROP_USE_REPL) - if (CPPINTEROP_USE_CLING) - set(cling_clang_interp clingInterpreter) - endif() - if (CPPINTEROP_USE_REPL) - set(cling_clang_interp clangInterpreter) - endif() +set(DLM + DynamicLibraryManager.cpp + DynamicLibraryManagerSymbol.cpp + Paths.cpp +) + +# Set sources based on whether Cling or Clang-REPL is used +if (CPPINTEROP_USE_CLING) + set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${DLM}) + set(DLM) + set(cling_clang_interp clingInterpreter) +endif() +if (CPPINTEROP_USE_REPL) + set(cling_clang_interp clangInterpreter) +endif() if(EMSCRIPTEN) set(link_libs @@ -53,68 +50,68 @@ else() ) endif() - if(NOT WIN32 AND NOT EMSCRIPTEN) - list(APPEND link_libs dl) - endif() +if(NOT WIN32 AND NOT EMSCRIPTEN) + list(APPEND link_libs dl) +endif() - # Get rid of libLLVM-X.so which is appended to the list of static libraries. - if (LLVM_LINK_LLVM_DYLIB) - set(new_libs ${link_libs}) - set(libs ${new_libs}) - while(NOT "${new_libs}" STREQUAL "") - foreach(lib ${new_libs}) - if(TARGET ${lib}) - get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES) - if (NOT transitive_libs) +# Get rid of libLLVM-X.so which is appended to the list of static libraries. +if (LLVM_LINK_LLVM_DYLIB) + set(new_libs ${link_libs}) + set(libs ${new_libs}) + while(NOT "${new_libs}" STREQUAL "") + foreach(lib ${new_libs}) + if(TARGET ${lib}) + get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES) + if (NOT transitive_libs) + continue() + endif() + foreach(transitive_lib ${transitive_libs}) + if(NOT TARGET ${transitive_lib}) continue() endif() - foreach(transitive_lib ${transitive_libs}) - if(NOT TARGET ${transitive_lib}) - continue() - endif() - get_target_property(lib_type ${transitive_lib} TYPE) - if("${lib_type}" STREQUAL "STATIC_LIBRARY") - list(APPEND static_transitive_libs ${transitive_lib}) - else() - # Filter our libLLVM.so and friends. - continue() - endif() - if(NOT ${transitive_lib} IN_LIST libs) - list(APPEND newer_libs ${transitive_lib}) - list(APPEND libs ${transitive_lib}) - endif() - endforeach(transitive_lib) - # Update the target properties with the list of only static libraries. - set_target_properties(${lib} PROPERTIES INTERFACE_LINK_LIBRARIES "${static_transitive_libs}") - set(static_transitive_libs "") - endif() - endforeach(lib) - set(new_libs ${newer_libs}) - set(newer_libs "") - endwhile() - # We just got rid of the libLLVM.so and other components shipped as shared - # libraries, we need to make up for the missing dependency. - list(APPEND LLVM_LINK_COMPONENTS - Coverage - FrontendHLSL - LTO - ) - # We will need to append the missing dependencies to pull in the right - # LLVM library dependencies. - list(APPEND link_libs - clangCodeGen - clangStaticAnalyzerCore - ) - endif(LLVM_LINK_LLVM_DYLIB) - add_llvm_library(clangCppInterOp - DISABLE_LLVM_LINK_LLVM_DYLIB - CppInterOp.cpp - CXCppInterOp.cpp - ${DLM} - LINK_LIBS - ${link_libs} - ) + get_target_property(lib_type ${transitive_lib} TYPE) + if("${lib_type}" STREQUAL "STATIC_LIBRARY") + list(APPEND static_transitive_libs ${transitive_lib}) + else() + # Filter our libLLVM.so and friends. + continue() + endif() + if(NOT ${transitive_lib} IN_LIST libs) + list(APPEND newer_libs ${transitive_lib}) + list(APPEND libs ${transitive_lib}) + endif() + endforeach(transitive_lib) + # Update the target properties with the list of only static libraries. + set_target_properties(${lib} PROPERTIES INTERFACE_LINK_LIBRARIES "${static_transitive_libs}") + set(static_transitive_libs "") + endif() + endforeach(lib) + set(new_libs ${newer_libs}) + set(newer_libs "") + endwhile() + # We just got rid of the libLLVM.so and other components shipped as shared + # libraries, we need to make up for the missing dependency. + list(APPEND LLVM_LINK_COMPONENTS + Coverage + FrontendHLSL + LTO + ) + # We will need to append the missing dependencies to pull in the right + # LLVM library dependencies. + list(APPEND link_libs + clangCodeGen + clangStaticAnalyzerCore + ) +endif(LLVM_LINK_LLVM_DYLIB) +add_llvm_library(clangCppInterOp + DISABLE_LLVM_LINK_LLVM_DYLIB + CppInterOp.cpp + CXCppInterOp.cpp + ${DLM} + LINK_LIBS + ${link_libs} +) if(EMSCRIPTEN) if(BUILD_SHARED_LIBS) @@ -141,19 +138,18 @@ if(EMSCRIPTEN) PRIVATE "SHELL: -Oz" PRIVATE "SHELL: -flto" ) -else() - target_link_options(clangCppInterOp - PRIVATE "SHELL: -s WASM_BIGINT" - ) -endif() + else() + target_link_options(clangCppInterOp + PRIVATE "SHELL: -s WASM_BIGINT" + ) + endif(BUILD_SHARED_LIBS) if (CPPINTEROP_ENABLE_TESTING) # When compiling Emscripten tests the CppInterOp library it links to is expected to be in the same folder as the compiled Javascript add_custom_command(TARGET clangCppInterOp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/unittests/CppInterOp/ ) endif(CPPINTEROP_ENABLE_TESTING) - -endif() +endif(EMSCRIPTEN) target_compile_definitions(clangCppInterOp PUBLIC "_CINDEX_LIB_") # workaround for the use of `CINDEX_LINKAGE` diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index f13b85f68..af04597c6 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -34,24 +34,24 @@ function(add_cppinterop_unittest name) add_dependencies(CppInterOpUnitTests ${name}) target_include_directories(${name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${GTEST_INCLUDE_DIR}) set_property(TARGET ${name} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -if(WIN32) - target_link_libraries(${name} PUBLIC ${ARG_LIBRARIES} ${gtest_libs}) - set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS "${MSVC_EXPORTS}") -else() - target_link_libraries(${name} PRIVATE ${ARG_LIBRARIES} ${gtest_libs} ${link_pthreads_lib}) -endif() -if(EMSCRIPTEN) - # Without this cmake will try and get node to run the html file. - # This guarantees that it runs the js file, and uses emsdks node. - add_test(NAME cppinterop-${name} COMMAND $ENV{EMSDK_NODE} ${name}.js) -else() - add_test(NAME cppinterop-${name} COMMAND ${name}) -endif() + if(WIN32) + target_link_libraries(${name} PUBLIC ${ARG_LIBRARIES} ${gtest_libs}) + set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS "${MSVC_EXPORTS}") + else() + target_link_libraries(${name} PRIVATE ${ARG_LIBRARIES} ${gtest_libs} ${link_pthreads_lib}) + endif() + if(EMSCRIPTEN) + # Without this cmake will try and get node to run the html file. + # This guarantees that it runs the js file, and uses emsdks node. + add_test(NAME cppinterop-${name} COMMAND $ENV{EMSDK_NODE} ${name}.js) + else() + add_test(NAME cppinterop-${name} COMMAND ${name}) + endif() set_tests_properties(cppinterop-${name} PROPERTIES - TIMEOUT "${TIMEOUT_VALUE}" - ENVIRONMENT "CPLUS_INCLUDE_PATH=${CMAKE_BINARY_DIR}/etc" - LABELS - DEPENDS) + TIMEOUT "${TIMEOUT_VALUE}" + ENVIRONMENT "CPLUS_INCLUDE_PATH=${CMAKE_BINARY_DIR}/etc" + LABELS + DEPENDS) # FIXME: Just call gtest_add_tests this function is available. #gtest_add_tests(${name} "${Arguments}" AUTO) endfunction()