From 7720248d742549e3b78ace8e95caf595e2eb821f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=85=D9=87=D8=AF=D9=8A=20=D8=B4=D9=8A=D9=86=D9=88=D9=86?= =?UTF-8?q?=20=28Mehdi=20Chinoune=29?= Date: Fri, 14 Jun 2024 14:12:10 +0100 Subject: [PATCH] [cmake] Fix building on MinGW-w64 --- export/cmake/CMakeLists.txt.export | 46 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/export/cmake/CMakeLists.txt.export b/export/cmake/CMakeLists.txt.export index 3e07c36e..be3ef1a5 100644 --- a/export/cmake/CMakeLists.txt.export +++ b/export/cmake/CMakeLists.txt.export @@ -260,15 +260,19 @@ endif() if (LIBINT2_BUILD_SHARED_AND_STATIC_LIBS) add_library(libint2 SHARED $) set_target_properties(libint2 PROPERTIES LIBRARY_OUTPUT_NAME int2 VERSION ${LIBINT_VERSION} SOVERSION 2) - if(MSVC) + if(WIN32) target_compile_definitions(libint2 PUBLIC _USE_MATH_DEFINES) - target_compile_options(libint2 PUBLIC "/EHsc") + if(MSVC) + target_compile_options(libint2 PUBLIC "/EHsc") + endif() endif() add_library(libint2-static STATIC $) set_target_properties(libint2-static PROPERTIES ARCHIVE_OUTPUT_NAME int2) - if(MSVC) + if(WIN32) target_compile_definitions(libint2-static PUBLIC _USE_MATH_DEFINES) - target_compile_options(libint2-static PUBLIC "/EHsc") + if(MSVC) + target_compile_options(libint2-static PUBLIC "/EHsc") + endif() endif() target_include_directories(libint2-static INTERFACE $ $ @@ -281,6 +285,7 @@ if (LIBINT2_BUILD_SHARED_AND_STATIC_LIBS) # Add libraries to the list of installed components install(TARGETS libint2-static EXPORT libint2 COMPONENT libint2 + RUNTIME DESTINATION "${LIBINT2_INSTALL_BINDIR}" LIBRARY DESTINATION "${LIBINT2_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${LIBINT2_INSTALL_LIBDIR}" # includes are installed by the include/CMakeLists.txt.include.export @@ -288,10 +293,9 @@ if (LIBINT2_BUILD_SHARED_AND_STATIC_LIBS) ) else() add_library(libint2 $) + set_target_properties(libint2 PROPERTIES OUTPUT_NAME int2) if (BUILD_SHARED_LIBS) - set_target_properties(libint2 PROPERTIES LIBRARY_OUTPUT_NAME int2 VERSION ${LIBINT_VERSION} SOVERSION 2) - else(BUILD_SHARED_LIBS) - set_target_properties(libint2 PROPERTIES ARCHIVE_OUTPUT_NAME int2) + set_target_properties(libint2 PROPERTIES VERSION ${LIBINT_VERSION} SOVERSION 2) endif(BUILD_SHARED_LIBS) endif() # In any case, there will exist a target named "int2": diminish code length by @@ -309,6 +313,7 @@ add_library(Libint2::int2 ALIAS libint2) # Add libraries to the list of installed components install(TARGETS libint2 EXPORT libint2 COMPONENT libint2 + RUNTIME DESTINATION "${LIBINT2_INSTALL_BINDIR}" LIBRARY DESTINATION "${LIBINT2_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${LIBINT2_INSTALL_LIBDIR}" # includes are installed by the include/CMakeLists.txt.include.export @@ -346,13 +351,18 @@ if (LIBINT_HAS_CXX_API) if (LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS) target_link_libraries(libint2_cxx INTERFACE Boost::headers) endif(LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS) - if(MSVC) - # MSVC does not include constants, unless _USE_MATH_DEFINES is defined. + if(WIN32) + # Windows does not include constants, unless _USE_MATH_DEFINES is defined. + target_compile_definitions( + libint2_cxx + INTERFACE + _USE_MATH_DEFINES + ) + if(MSVC) # _CRT_* to squash some getenv, strdup, strncpy, ctime, fopen warnings target_compile_definitions( libint2_cxx INTERFACE - _USE_MATH_DEFINES _CRT_NONSTDC_NO_DEPRECATE _CRT_NONSTDC_NO_WARNINGS _CRT_SECURE_NO_WARNINGS @@ -363,6 +373,7 @@ if (LIBINT_HAS_CXX_API) INTERFACE "/EHsc" ) + endif() endif() get_filename_component(DATADIR_ABSOLUTE "${CMAKE_INSTALL_PREFIX}/${LIBINT2_INSTALL_DATADIR}" ABSOLUTE) target_compile_definitions(libint2_cxx INTERFACE @@ -383,6 +394,7 @@ if (LIBINT_HAS_CXX_API) # Add library to the list of installed components install(TARGETS libint2_cxx EXPORT libint2 COMPONENT cxx + RUNTIME DESTINATION "${LIBINT2_INSTALL_BINDIR}" LIBRARY DESTINATION "${LIBINT2_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${LIBINT2_INSTALL_LIBDIR}" # includes are installed by the include/CMakeLists.txt.include.export @@ -400,10 +412,12 @@ add_custom_target_subproject(libint2 check USES_TERMINAL COMMAND ${CMAKE_CTEST_C add_executable(eritest-libint2 EXCLUDE_FROM_ALL tests/eri/test.cc) target_link_libraries(eritest-libint2 ${int2_library}) target_include_directories(eritest-libint2 PRIVATE ${PROJECT_SOURCE_DIR}/tests/eri) -if(MSVC) - # TODO on future target pass, def should be added to the L2 target, not added to test - target_compile_definitions(eritest-libint2 PUBLIC _USE_MATH_DEFINES) +if(WIN32) + # TODO on future target pass, def should be added to the L2 target, not added to test + target_compile_definitions(eritest-libint2 PUBLIC _USE_MATH_DEFINES) + if(MSVC) target_compile_options(eritest-libint2 PUBLIC "/EHsc") + endif() endif() add_test(libint2/eritest/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target eritest-libint2) @@ -514,8 +528,8 @@ if (ENABLE_FORTRAN) # specify the location of modules set(CMAKE_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/fortran/modules/") - # preprocess libint2.h ... this is a guess for UNIX systems only - if (UNIX) + # preprocess libint2.h ... this is a guess for non-MSVC compilers + if (NOT MSVC) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran) @@ -527,7 +541,7 @@ if (ENABLE_FORTRAN) COMMENT "Generating libint2.h.i" ) else() - message(FATAL_ERROR "Cannot run preprocessor on non-Unix systems, disable Fortran to proceed") + message(FATAL_ERROR "Cannot run preprocessor with MSVC compilers, disable Fortran to proceed") endif() # translated Libint_t