From 73a7378ddb0522ced87e57566ead19525c2c5eb6 Mon Sep 17 00:00:00 2001 From: Paolo Tosco Date: Thu, 22 May 2025 05:08:01 +0200 Subject: [PATCH] Avoid a large number of warnings when building MinimalLib with emscripten (#8545) * - avoid a large number of warnings when building MinimalLib with emscripten, which does not support SHARED - fix indentation in CoordGen CMakeLists.txt * disable RDK_USE_BOOST_STACKTRACE on emscripten platform * revert change done by mistake --------- Co-authored-by: ptosco --- CMakeLists.txt | 24 +++++++++++++--------- Code/GraphMol/CMakeLists.txt | 2 +- Code/GraphMol/MolDraw2D/CMakeLists.txt | 8 ++++---- Code/MinimalLib/CMakeLists.txt | 22 ++++++++++---------- Code/cmake/Modules/RDKitUtils.cmake | 2 +- External/CoordGen/CMakeLists.txt | 28 +++++++++++++------------- 6 files changed, 45 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a42075cd5..903befc4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,9 +90,15 @@ if(NOT MSVC) endif() endif() -if(NOT UNIX OR APPLE OR CYGWIN) +# Detect clang, which masquerades as gcc. CMake 2.6 doesn't know how to +# detect it. +string(REGEX MATCH "clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER}") +# Detect emcc +string(REGEX MATCH "Emscripten" CMAKE_COMPILER_IS_EMCC "${CMAKE_SYSTEM_NAME}") + +if(NOT UNIX OR APPLE OR CYGWIN OR CMAKE_COMPILER_IS_EMCC) if(RDK_USE_BOOST_STACKTRACE) - MESSAGE("Disabling boost::stacktrace on non-linux platform") + MESSAGE("Disabling boost::stacktrace on non-linux and emscripten platforms") set(RDK_USE_BOOST_STACKTRACE OFF) endif(RDK_USE_BOOST_STACKTRACE) endif() @@ -108,8 +114,12 @@ if(RDK_SWIG_STATIC AND RDK_BUILD_SWIG_WRAPPERS) set(RDK_INSTALL_STATIC_LIBS ON CACHE BOOL "install the rdkit static libraries" FORCE) endif(NOT MSVC AND NOT RDK_INSTALL_STATIC_LIBS) endif() - -if((NOT (MSVC AND (NOT RDK_INSTALL_DLLS_MSVC))) AND NOT (WIN32 AND RDK_INSTALL_STATIC_LIBS)) +if ((MSVC AND (NOT RDK_INSTALL_DLLS_MSVC)) OR (WIN32 AND RDK_INSTALL_STATIC_LIBS) OR RDK_BUILD_MINIMAL_LIB) + set(RDK_BUILD_STATIC_LIBS_ONLY ON) +else() + set(RDK_BUILD_STATIC_LIBS_ONLY OFF) +endif() +if(NOT RDK_BUILD_STATIC_LIBS_ONLY) add_definitions(-DRDKIT_DYN_LINK) endif() @@ -247,12 +257,6 @@ if(RDK_BUILD_YAEHMOP_SUPPORT) add_definitions(-DRDK_BUILD_YAEHMOP_SUPPORT) endif() -# Detect clang, which masquerades as gcc. CMake 2.6 doesn't know how to -# detect it. -string(REGEX MATCH "clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER}") -# Detect emcc -string(REGEX MATCH "Emscripten" CMAKE_COMPILER_IS_EMCC "${CMAKE_SYSTEM_NAME}") - if(CMAKE_SIZEOF_VOID_P EQUAL 4) target_compile_definitions(rdkit_base INTERFACE "-DRDK_32BIT_BUILD") else() diff --git a/Code/GraphMol/CMakeLists.txt b/Code/GraphMol/CMakeLists.txt index a08a9775a..8f8f5ffe3 100644 --- a/Code/GraphMol/CMakeLists.txt +++ b/Code/GraphMol/CMakeLists.txt @@ -14,7 +14,7 @@ rdkit_library(GraphMol target_compile_definitions(GraphMol PRIVATE RDKIT_GRAPHMOL_BUILD) if (RDK_USE_URF) target_link_libraries(GraphMol PUBLIC ${RDK_URF_LIBS}) - if (NOT WIN32 AND RDK_INSTALL_STATIC_LIBS) + if (RDK_INSTALL_STATIC_LIBS AND NOT RDK_BUILD_STATIC_LIBS_ONLY) target_link_libraries(GraphMol_static PUBLIC ${RDK_URF_LIBS}_static) endif () endif () diff --git a/Code/GraphMol/MolDraw2D/CMakeLists.txt b/Code/GraphMol/MolDraw2D/CMakeLists.txt index 58a8a3ebc..9bdb1ed24 100644 --- a/Code/GraphMol/MolDraw2D/CMakeLists.txt +++ b/Code/GraphMol/MolDraw2D/CMakeLists.txt @@ -59,7 +59,7 @@ if (RDK_BUILD_CAIRO_SUPPORT) target_compile_definitions(MolDraw2D PUBLIC "-DRDK_BUILD_CAIRO_SUPPORT") target_link_libraries(MolDraw2D PUBLIC Cairo::Cairo) target_sources(MolDraw2D PRIVATE MolDraw2DCairo.cpp DrawTextCairo.cpp) - if (RDK_INSTALL_STATIC_LIBS AND NOT WIN32) + if (RDK_INSTALL_STATIC_LIBS AND NOT RDK_BUILD_STATIC_LIBS_ONLY) target_compile_definitions(MolDraw2D_static PUBLIC "-DRDK_BUILD_CAIRO_SUPPORT") target_link_libraries(MolDraw2D_static PUBLIC Cairo::Cairo) target_sources(MolDraw2D_static PRIVATE MolDraw2DCairo.cpp DrawTextCairo.cpp) @@ -71,7 +71,7 @@ if (RDK_BUILD_FREETYPE_SUPPORT) target_compile_definitions(MolDraw2D PUBLIC "-DRDK_BUILD_FREETYPE_SUPPORT") target_sources(MolDraw2D PRIVATE DrawText.cpp DrawTextFT.cpp DrawTextFTSVG.cpp DrawTextFTJS.cpp) - if (RDK_INSTALL_STATIC_LIBS AND NOT WIN32) + if (RDK_INSTALL_STATIC_LIBS AND NOT RDK_BUILD_STATIC_LIBS_ONLY) target_compile_definitions(MolDraw2D_static PUBLIC "-DRDK_BUILD_FREETYPE_SUPPORT") target_sources(MolDraw2D_static PRIVATE DrawText.cpp DrawTextFT.cpp DrawTextFTSVG.cpp DrawTextFTJS.cpp) @@ -84,13 +84,13 @@ if (RDK_BUILD_FREETYPE_SUPPORT) find_package(Freetype REQUIRED) target_include_directories(MolDraw2D PUBLIC ${FREETYPE_INCLUDE_DIRS}) target_link_libraries(MolDraw2D PUBLIC ${FREETYPE_LIBRARIES}) - if (RDK_INSTALL_STATIC_LIBS AND NOT WIN32) + if (RDK_INSTALL_STATIC_LIBS AND NOT RDK_BUILD_STATIC_LIBS_ONLY) target_include_directories(MolDraw2D_static PUBLIC ${FREETYPE_INCLUDE_DIRS}) target_link_libraries(MolDraw2D_static PUBLIC ${FREETYPE_LIBRARIES}) endif () if (RDK_BUILD_CAIRO_SUPPORT) target_sources(MolDraw2D PRIVATE DrawTextFTCairo.cpp) - if (RDK_INSTALL_STATIC_LIBS AND NOT WIN32) + if (RDK_INSTALL_STATIC_LIBS AND NOT RDK_BUILD_STATIC_LIBS_ONLY) target_sources(MolDraw2D_static PRIVATE DrawTextFTCairo.cpp) endif () endif () diff --git a/Code/MinimalLib/CMakeLists.txt b/Code/MinimalLib/CMakeLists.txt index 627e95e28..6ac61bab1 100644 --- a/Code/MinimalLib/CMakeLists.txt +++ b/Code/MinimalLib/CMakeLists.txt @@ -2,34 +2,34 @@ include_directories(${RDKit_ExternalDir}) include_directories(${RDKit_ExternalDir}/rapidjson-1.1.0/include) if(RDK_BUILD_MINIMAL_LIB) - set(MINIMAL_LIB_LIBRARIES "MolInterchange_static;Abbreviations_static;" - "CIPLabeler_static;MolDraw2D_static;Depictor_static;" - "Descriptors_static;SubstructMatch_static;FileParsers_static;" - "SmilesParse_static;GraphMol_static;RDGeometryLib_static;" - "RDGeneral_static;RGroupDecomposition_static;Fingerprints_static") + set(MINIMAL_LIB_LIBRARIES "MolInterchange;Abbreviations;" + "CIPLabeler;MolDraw2D;Depictor;" + "Descriptors;SubstructMatch;FileParsers;" + "SmilesParse;GraphMol;RDGeometryLib;" + "RDGeneral;RGroupDecomposition;Fingerprints") if(RDK_BUILD_INCHI_SUPPORT) add_definitions(-DRDK_BUILD_INCHI_SUPPORT) - set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};RDInchiLib_static") + set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};RDInchiLib") endif() if(RDK_BUILD_MINIMAL_LIB_RXN) add_definitions(-DRDK_BUILD_MINIMAL_LIB_RXN) - set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};ChemReactions_static") + set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};ChemReactions") endif() if(RDK_BUILD_MINIMAL_LIB_SUBSTRUCTLIBRARY) add_definitions(-DRDK_BUILD_MINIMAL_LIB_SUBSTRUCTLIBRARY) - set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};SubstructLibrary_static") + set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};SubstructLibrary") endif() if(RDK_BUILD_MINIMAL_LIB_MCS) add_definitions(-DRDK_BUILD_MINIMAL_LIB_MCS) - set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};FMCS_static") + set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};FMCS") endif() if(RDK_BUILD_MINIMAL_LIB_MMPA) add_definitions(-DRDK_BUILD_MINIMAL_LIB_MMPA) - set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};MMPA_static") + set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};MMPA") endif() if(RDK_BUILD_MINIMAL_LIB_MOLZIP) add_definitions(-DRDK_BUILD_MINIMAL_LIB_MOLZIP) - set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};ChemTransforms_static") + set(MINIMAL_LIB_LIBRARIES "${MINIMAL_LIB_LIBRARIES};ChemTransforms") endif() if(RDK_BUILD_FREETYPE_SUPPORT) if( ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") diff --git a/Code/cmake/Modules/RDKitUtils.cmake b/Code/cmake/Modules/RDKitUtils.cmake index 40bd8b31b..5b1b00a21 100644 --- a/Code/cmake/Modules/RDKitUtils.cmake +++ b/Code/cmake/Modules/RDKitUtils.cmake @@ -46,7 +46,7 @@ macro(rdkit_library) break() endif() endforeach() - if((MSVC AND (NOT RDK_INSTALL_DLLS_MSVC)) OR (WIN32 AND RDK_INSTALL_STATIC_LIBS)) + if(RDK_BUILD_STATIC_LIBS_ONLY) add_library(${RDKLIB_NAME} ${RDKLIB_SOURCES}) target_link_libraries(${RDKLIB_NAME} PUBLIC rdkit_base) if(RDK_INSTALL_DEV_COMPONENT) diff --git a/External/CoordGen/CMakeLists.txt b/External/CoordGen/CMakeLists.txt index f6b06b6b5..5aeea9583 100644 --- a/External/CoordGen/CMakeLists.txt +++ b/External/CoordGen/CMakeLists.txt @@ -68,15 +68,15 @@ if(RDK_BUILD_COORDGEN_SUPPORT) endif() if(NOT EXISTS "${COORDGEN_DIR}/sketcherMinimizer.h") - set(RELEASE_NO "3.0.2") - set(MD5 "bc9dabbbb2b99ae426f3a1bf16c4d3cc") - downloadAndCheckMD5("https://github.com/schrodinger/coordgenlibs/archive/v${RELEASE_NO}.tar.gz" - "${CMAKE_CURRENT_SOURCE_DIR}/coordgenlibs-${RELEASE_NO}.tar.gz" ${MD5}) - execute_process(COMMAND ${CMAKE_COMMAND} -E tar zxf - ${CMAKE_CURRENT_SOURCE_DIR}/coordgenlibs-${RELEASE_NO}.tar.gz - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + set(RELEASE_NO "3.0.2") + set(MD5 "bc9dabbbb2b99ae426f3a1bf16c4d3cc") + downloadAndCheckMD5("https://github.com/schrodinger/coordgenlibs/archive/v${RELEASE_NO}.tar.gz" + "${CMAKE_CURRENT_SOURCE_DIR}/coordgenlibs-${RELEASE_NO}.tar.gz" ${MD5}) + execute_process(COMMAND ${CMAKE_COMMAND} -E tar zxf + ${CMAKE_CURRENT_SOURCE_DIR}/coordgenlibs-${RELEASE_NO}.tar.gz + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - file(RENAME "coordgenlibs-${RELEASE_NO}" "${COORDGEN_DIR}") + file(RENAME "coordgenlibs-${RELEASE_NO}" "${COORDGEN_DIR}") else() message("-- Found coordgenlibs source in ${COORDGEN_DIR}") endif() @@ -85,12 +85,12 @@ if(RDK_BUILD_COORDGEN_SUPPORT) CACHE STRING "CoordGen Include File" FORCE) file(GLOB CGSOURCES "${COORDGEN_DIR}/*.cpp") rdkit_library(coordgen ${CGSOURCES} SHARED) -if(CMAKE_C_COMPILER_ID STREQUAL "Clang") - target_compile_options(coordgen PUBLIC -Wno-unused-but-set-variable) -if(RDK_INSTALL_STATIC_LIBS) - target_compile_options(coordgen_static PUBLIC -Wno-unused-but-set-variable) -endif() -endif() + if(CMAKE_C_COMPILER_ID STREQUAL "Clang") + target_compile_options(coordgen PUBLIC -Wno-unused-but-set-variable) + if(RDK_INSTALL_STATIC_LIBS AND NOT RDK_BUILD_STATIC_LIBS_ONLY) + target_compile_options(coordgen_static PUBLIC -Wno-unused-but-set-variable) + endif() + endif() install(TARGETS coordgen DESTINATION ${RDKit_LibDir}) set(RDK_COORDGEN_LIBS coordgen CACHE STRING "the external libraries" FORCE)