Skip to content

Commit

Permalink
[cmake] Fix building on MinGW-w64
Browse files Browse the repository at this point in the history
  • Loading branch information
MehdiChinoune committed Jun 14, 2024
1 parent d443cee commit 7720248
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions export/cmake/CMakeLists.txt.export
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,19 @@ endif()
if (LIBINT2_BUILD_SHARED_AND_STATIC_LIBS)
add_library(libint2 SHARED $<TARGET_OBJECTS:libint2_obj>)
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 $<TARGET_OBJECTS:libint2_obj>)
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
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
Expand All @@ -281,17 +285,17 @@ 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
# INCLUDES DESTINATION "${LIBINT2_INSTALL_INCLUDEDIR}"
)
else()
add_library(libint2 $<TARGET_OBJECTS:libint2_obj>)
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
Expand All @@ -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
Expand Down Expand Up @@ -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 <cmath> constants, unless _USE_MATH_DEFINES is defined.
if(WIN32)
# Windows does not include <cmath> 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 7720248

Please sign in to comment.