Skip to content

Commit

Permalink
chore: allow build using MinGW on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbuechner committed Jul 10, 2023
1 parent ffea634 commit 9d1d5f0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
40 changes: 20 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25)

option(OCCUTILS_BUILD_TESTS "Build tests" OFF)
if (OCCUTILS_BUILD_TESTS)
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
endif ()

set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_LIST_DIR}/vcpkg/triplets" CACHE STRING "")
Expand All @@ -16,7 +16,7 @@ set(cmake_package_name occutils CACHE INTERNAL "")

# Set default build to release
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif ()

# Compiler config
Expand All @@ -25,20 +25,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

# make sure __cplusplus is defined when using msvc and enable parallel build
if (MSVC)
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus /MP")
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus /MP")
endif ()

set(CMAKE_CXX_EXTENSIONS OFF)

if (CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS")
set(CMAKE_CXX_EXTENSIONS ON)
if (CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
set(CMAKE_CXX_EXTENSIONS ON)
endif ()

# These commands only run if this is the main project
if (CMAKE_PROJECT_NAME STREQUAL "occutils")
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
# make it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
# make it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
endif ()

# warning options
Expand All @@ -62,22 +62,22 @@ find_package(GTest CONFIG REQUIRED)
cxx_library(${PROJECT_NAME} src/occutils-all.cc)

target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
${OpenCASCADE_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
)
${OpenCASCADE_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
)

if (OCCUTILS_BUILD_WARNINGS)
target_enable_warnings(${PROJECT_NAME})
target_enable_warnings(${PROJECT_NAME})
endif ()

# If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled
# in via add_subdirectory() rather than being a standalone build).
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>"
)
endif ()

# Configure install
Expand Down Expand Up @@ -110,7 +110,7 @@ install(EXPORT ${PROJECT_NAME} DESTINATION ${export_dest_dir} NAMESPACE ${PROJEC

# Configure package config file
configure_package_config_file("${project_config_in}" "${project_config_out}"
INSTALL_DESTINATION ${export_dest_dir})
INSTALL_DESTINATION ${export_dest_dir})

# Write version config file
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
Expand All @@ -120,9 +120,9 @@ install(FILES "${project_config_out}" "${version_config_file}" DESTINATION "${ex

# Testing
if (OCCUTILS_BUILD_TESTS)
message(STATUS "Generating tests")
enable_testing()
add_subdirectory(test)
message(STATUS "Generating tests")
enable_testing()
add_subdirectory(test)
endif ()

# Packaging
Expand Down
14 changes: 11 additions & 3 deletions vcpkg/ports/opencascade/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ vcpkg_from_github(
fix-depend-freetype.patch
)

# message("VCPKG_CMAKE_SYSTEM_NAME: ${VCPKG_CMAKE_SYSTEM_NAME}")

# MinGW compiler does generate import libraries (.dll.a files) for DLLs on Windows.
# Suppresses Warning: Import libraries were not present (only looking for ".lib" files)
if (WIN32 AND VCPKG_CMAKE_SYSTEM_NAME STREQUAL "MinGW")
set(VCPKG_POLICY_DLLS_WITHOUT_LIBS enabled)
endif ()

if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set(BUILD_TYPE "Shared")
else ()
Expand All @@ -26,7 +34,7 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS

# VTK option in opencascade not currently supported because only 6.1.0 is supported but vcpkg has >= 9.0

# We turn off BUILD_MODULE_Draw as it requires TCL 8.6 and TK 8.6 specifically which conflicts with vcpkg only having TCL 9.0
# We turn off BUILD_MODULE_Draw as it requires TCL 8.6 and TK 8.6 specifically which conflicts with vcpkg only having TCL 9.0
# And pre-built ActiveTCL binaries are behind a marketing wall :(
# We use the Unix install layout for Windows as it matches vcpkg
vcpkg_cmake_configure(
Expand Down Expand Up @@ -69,7 +77,7 @@ foreach (file_name IN LISTS files)
endforeach ()

# Remove libd to lib, libd just has cmake files we dont want too
if (WIN32)
if (WIN32 AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "MinGW")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib")
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/libd" "${CURRENT_PACKAGES_DIR}/debug/lib")
endif ()
Expand All @@ -79,7 +87,7 @@ file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")

if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
# debug creates libd and bind directories that need moving
if (WIN32)
if (WIN32 AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "MinGW")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin")
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/bind" "${CURRENT_PACKAGES_DIR}/debug/bin")
endif ()
Expand Down
10 changes: 10 additions & 0 deletions vcpkg/triplets/x64-mingw-static.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_ENV_PASSTHROUGH PATH)

set(VCPKG_CMAKE_SYSTEM_NAME MinGW)

if (PORT MATCHES "opencascade")
set(VCPKG_LIBRARY_LINKAGE dynamic)
endif ()

0 comments on commit 9d1d5f0

Please sign in to comment.