From 78f10dd0e0a15690fd76339ed61fc2a33e7b8e8f Mon Sep 17 00:00:00 2001 From: Gyusun Yeom Date: Fri, 5 Mar 2021 21:55:15 +0900 Subject: [PATCH 1/2] Fix shared library build for mingw --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af80c65..9b61307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,13 +178,20 @@ if(glew-cmake_BUILD_SHARED) endif() target_compile_definitions(libglew_shared PRIVATE GLEW_BUILD) + if(MINGW) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(libglew_shared PRIVATE -nostdlib) + else() + target_link_libraries(libglew_shared PRIVATE -nostdlib) + endif() + endif() list(APPEND GLEW_TARGETS libglew_shared) endif() foreach(GLEW_TARGET ${GLEW_TARGETS}) target_compile_definitions(${GLEW_TARGET} PUBLIC ${DEFINITIONS}) target_include_directories(${GLEW_TARGET} PUBLIC ${INCLUDE_DIR}) - target_link_libraries(${GLEW_TARGET} ${LIBRARIES}) + target_link_libraries(${GLEW_TARGET} PUBLIC ${LIBRARIES}) set_target_properties(${GLEW_TARGET} PROPERTIES VERSION ${GLEW_VERSION}) endforeach() From f61e3235842d4a3ef4d7339c2bbc07462718e65a Mon Sep 17 00:00:00 2001 From: Gyusun Yeom Date: Fri, 5 Mar 2021 22:09:17 +0900 Subject: [PATCH 2/2] Build test with mingw --- .github/workflows/cmake.yml | 23 +++++++++++++++++++++++ glew-cmake/mingw.cmake | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 glew-cmake/mingw.cmake diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b793141..6fd30c7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -132,6 +132,29 @@ jobs: shell: bash run: test -e lib/libGLEW.a + build_mingw: + # The CMake configure and build commands are platform agnostic and should work equally + # well on Windows or Mac. You can convert this to a matrix build if you need + # cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + container: ubuntu:18.04 + + steps: + - uses: actions/checkout@v2 + + - name: Install dependencies + run: apt update && apt install -y cmake g++-mingw-w64-x86-64 make libgl1-mesa-dev libx11-dev libxext-dev + + - name: Configure CMake + shell: bash + run: cmake . -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE="$GITHUB_WORKSPACE/glew-cmake/mingw.cmake" + + - name: Build test + shell: bash + run: cmake --build . + + build_mac: runs-on: macos-latest diff --git a/glew-cmake/mingw.cmake b/glew-cmake/mingw.cmake new file mode 100644 index 0000000..d834751 --- /dev/null +++ b/glew-cmake/mingw.cmake @@ -0,0 +1,16 @@ +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) + +# cross compilers to use for C, C++ and Fortran +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +# target environment on the build host system +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) + +# modify default behavior of FIND_XXX() commands +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +