Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Windows CMake setup + Stand-alone examples #720

Merged
merged 11 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/windows-cygwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:

- name: configure
run: |
path C:\tools\cygwin\bin;%GITHUB_WORKSPACE%\build\windows_shared_library
path C:\tools\cygwin\bin
mkdir build
cd build
bash -c "cmake -DCMAKE_CXX_FLAGS=-Wa,-mbig-obj -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DGINKGO_COMPILER_FLAGS=${{ matrix.config.cflags }} .."
bash -c "cmake -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DGINKGO_COMPILER_FLAGS=${{ matrix.config.cflags }} .."
bash -c "make -j4"
bash -c "ctest . --output-on-failure"
shell: cmd
Expand All @@ -49,5 +49,5 @@ jobs:
path C:\tools\cygwin\bin
cd build
bash -c "make install"
bash -c "export PATH=/usr/local/lib:$PATH && make test_install"
bash -c "export PATH=/usr/local/bin:$PATH && make test_install"
shell: cmd
6 changes: 3 additions & 3 deletions .github/workflows/windows-mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ jobs:
bcdedit /set IncreaseUserVa 3072
editbin /LARGEADDRESSAWARE "C:\Program Files\Git\mingw64\bin\cc1plus.exe"
path %PATH:C:\Program Files\Git\bin;=%
path %PATH:C:\Program Files\Git\usr\bin;=%;%GITHUB_WORKSPACE%\build\windows_shared_library
path %PATH:C:\Program Files\Git\usr\bin;=%
mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_CXX_FLAGS=-Wa,-mbig-obj -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DGINKGO_COMPILER_FLAGS=${{ matrix.config.cflags }} ..
cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DGINKGO_COMPILER_FLAGS=${{ matrix.config.cflags }} ..
cmake --build . -j4
ctest . --output-on-failure
shell: cmd

- name: install
run: |
set PATH=%PATH:C:\Program Files\Git\bin;=%
set PATH=%PATH:C:\Program Files\Git\usr\bin;=%;C:\Program Files (x86)\Ginkgo\lib
set PATH=%PATH:C:\Program Files\Git\usr\bin;=%;C:\Program Files (x86)\Ginkgo\bin
cd build
cmake --install .
cmake --build . --target test_install
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/windows-msvc-cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ jobs:
$env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.."
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
refreshenv
$env:PATH="$env:PATH;$pwd\build\windows_shared_library"
mkdir build
cd build
cmake -DCMAKE_CXX_FLAGS=/bigobj -DGINKGO_BUILD_CUDA=ON -DGINKGO_BUILD_OMP=OFF -DGINKGO_MIXED_PRECISION=${{ matrix.config.mixed }} -DGINKGO_CUDA_ARCHITECTURES=60 ..
cmake -DGINKGO_BUILD_CUDA=ON -DGINKGO_BUILD_OMP=OFF -DGINKGO_MIXED_PRECISION=${{ matrix.config.mixed }} -DGINKGO_CUDA_ARCHITECTURES=60 ..
cmake --build . -j4 --config Release
5 changes: 2 additions & 3 deletions .github/workflows/windows-msvc-ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ jobs:

- name: configure
run: |
$env:PATH="$env:PATH;$pwd\build\windows_shared_library"
mkdir build
cd build
cmake -DCMAKE_CXX_FLAGS=/bigobj -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DCMAKE_CXX_FLAGS_DEBUG="/MDd /Zi /Ob1 /Od /RTC1" -DGINKGO_BUILD_CUDA=OFF -DGINKGO_BUILD_OMP=OFF -DGINKGO_MIXED_PRECISION=${{ matrix.config.mixed }} ..
cmake -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DCMAKE_CXX_FLAGS_DEBUG="/MDd /Zi /Ob1 /Od /RTC1" -DGINKGO_BUILD_CUDA=OFF -DGINKGO_BUILD_OMP=OFF -DGINKGO_MIXED_PRECISION=${{ matrix.config.mixed }} ..
cmake --build . -j4 --config ${{ matrix.config.build_type }}
ctest . -C ${{ matrix.config.build_type }} --output-on-failure

- name: install
run: |
$env:PATH="$env:PATH;C:\Program Files (x86)\Ginkgo\lib"
$env:PATH="$env:PATH;C:\Program Files (x86)\Ginkgo\bin"
cd build
cmake --install . --config ${{ matrix.config.build_type }}
cmake --build . --target test_install --config ${{ matrix.config.build_type }}
44 changes: 15 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ include(cmake/hip_path.cmake)
include(cmake/autodetect_executors.cmake)
include(cmake/build_type_helpers.cmake)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif()
if (MINGW OR CYGWIN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
endif()

# Ginkgo configuration options
option(GINKGO_DEVEL_TOOLS "Add development tools to the build system" OFF)
option(GINKGO_BUILD_TESTS "Generate build files for unit tests" ON)
Expand Down Expand Up @@ -107,19 +114,6 @@ if(GINKGO_BENCHMARK_ENABLE_TUNING)
set(GINKGO_BUILD_EXAMPLES OFF)
endif()

if(BUILD_SHARED_LIBS AND (WIN32 OR CYGWIN) AND (GINKGO_BUILD_TESTS OR GINKGO_BUILD_EXAMPLES OR GINKGO_BUILD_BENCHMARKS))
# Change shared libraries output only if this build has executable program
# with shared libraries.
set(GINKGO_CHANGED_SHARED_LIBRARY TRUE)
option(GINKGO_CHECK_PATH "Tell Ginkgo to check if the environment variable PATH is available for this build." ON)
set(GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH "windows_shared_library" CACHE STRING
"Set Ginkgo's shared library relative path in windows. Current default is `windows_shared_library`. \
This absolute path ${PROJECT_BINARY_DIR}/GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH must be in the environment variable PATH.")
set(GINKGO_WINDOWS_SHARED_LIBRARY_PATH ${PROJECT_BINARY_DIR}/${GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH})
else()
set(GINKGO_CHANGED_SHARED_LIBRARY FALSE)
endif()

if(GINKGO_BUILD_TESTS AND (GINKGO_BUILD_CUDA OR GINKGO_BUILD_OMP OR GINKGO_BUILD_HIP OR GINKGO_BUILD_DPCPP))
message(STATUS "GINKGO_BUILD_TESTS is ON, enabling GINKGO_BUILD_REFERENCE")
set(GINKGO_BUILD_REFERENCE ON CACHE BOOL "Compile reference CPU kernels" FORCE)
Expand Down Expand Up @@ -220,22 +214,6 @@ if(GINKGO_BUILD_HIP)
endif()
endif()


if(MSVC)
# This is modified from
# https://gitlab.kitware.com/cmake/community/wikis/FAQ#dynamic-replace
include(cmake/windows_helpers.cmake)
if(BUILD_SHARED_LIBS)
ginkgo_switch_to_windows_dynamic("CXX")
ginkgo_switch_to_windows_dynamic("C")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
else()
ginkgo_switch_to_windows_static("CXX")
ginkgo_switch_to_windows_static("C")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS FALSE)
endif()
endif()

# Try to find the third party packages before using our subdirectories
include(cmake/package_helpers.cmake)
ginkgo_find_package(GTest "GTest::GTest;GTest::Main" FALSE 1.8.1)
Expand All @@ -254,6 +232,14 @@ add_subdirectory(third_party) # Third-party tools and libraries
include(cmake/build_helpers.cmake)
include(cmake/install_helpers.cmake)

if(MSVC)
if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
else()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS FALSE)
endif()
endif()

configure_file(${Ginkgo_SOURCE_DIR}/include/ginkgo/config.hpp.in
${Ginkgo_BINARY_DIR}/include/ginkgo/config.hpp @ONLY)

Expand Down
54 changes: 3 additions & 51 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ Ginkgo adds the following additional switches to control what is being built:
this option see the
[`ARCHITECTURES` specification list](https://github.com/ginkgo-project/CudaArchitectureSelector/blob/master/CudaArchitectureSelector.cmake#L58)
section in the documentation of the CudaArchitectureSelector CMake module.
* `-DGINKGO_WINDOWS_SHARED_LIBRARY_RELPATH=<path>` where <path> is a relative
path built with `PROJECT_BINARY_DIR`. Users must add the absolute path
(`PROJECT_BINARY_DIR`/`GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH`) into the
environment variable PATH when building shared libraries and executable
program, default is `windows_shared_library`.
* `-DGINKGO_CHECK_PATH={ON, OFF}` checks if the environment variable PATH is valid.
It is checked only when building shared libraries and executable program,
default is `ON`.

For example, to build everything (in debug mode), use:

Expand All @@ -139,50 +131,10 @@ generators. Other CMake generators are untested.

### Building Ginkgo in Windows
Depending on the configuration settings, some manual work might be required:
* Build Ginkgo as shared library:
Add `PROJECT_BINARY_DIR/GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH` into the environment variable `PATH`.
`GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH` is `windows_shared_library` by default. More Details are available in the [Installation page](./INSTALL.md).
* cmd: `set PATH=<PROJECT_BINARY_DIR/GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH>;%PATH%`
* powershell: `$env:PATH="<PROJECT_BINARY_DIR/GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH>;$env:PATH"`

CMake will give the following error message if the path is not correct.
```
Did not find this build in the environment variable PATH. Please add <path> into the environment variable PATH.
```
where `<path>` is the needed `<PROJECT_BINARY_DIR/GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH>`.
* Build Ginkgo with Debug mode:
Some Debug build specific issues can appear depending on the machine and environment. The known issues are the following:
1. `bigobj` issue: encountering `too many sections` needs the compilation flags `/bigobj` or `-Wa,-mbig-obj`
2. `ld` issue: encountering `ld: error: export ordinal too large` needs the compilation flag `-O1`

The following are the details for different environments:
* _Microsoft Visual Studio_:
1. `bigobj` issue
* `cmake -DCMAKE_CXX_FLAGS=/bigobj <other parameters> <source_folder>` which might overwrite the default settings.
* add `/bigobj` into the environment variable `CXXFLAGS` (only available in the first cmake configuration)
* cmd: `set CXXFLAGS=/bigobj`
* powershell: `$env:CXXFLAGS=/bigobj`
2. `ld` issue (_Microsoft Visual Studio_ does not have this issue)
* _Cygwin_:
1. `bigobj` issue
* add `-Wa,-mbig-obj -O1` into the environment variable `CXXFLAGS` (only available in the first cmake configuration)
* `export CXXFLAGS="-Wa,-mbig-obj -O1"`
* `cmake -DCMAKE_CXX_FLAGS=-Wa,-mbig-obj <other parameters> <source_folder>`, which might overwrite the default settings.
2. `ld` issue (If building Ginkgo as static library, this is not needed)
* `cmake -DGINKGO_COMPILER_FLAGS="-Wpedantic -O1" <other parameters> <source_folder>` (`GINKGO_COMPILER_FLAGS` is `-Wpedantic` by default)
* add `-O1` in the environement variable `CXX_FLAGS` or `CMAKE_CXX_FLAGS`
* _MinGW_:
1. `bigobj` issue
* add `-Wa,-mbig-obj -O1` into the environment variable `CXXFLAGS` (only available in the first cmake configuration)
* cmd: `set CXXFLAGS="-Wa,-mbig-obj"`
* powershell: `$env:CXXFLAGS="-Wa,-mbig-obj"`
* `cmake -DCMAKE_CXX_FLAGS=-Wa,-mbig-obj <other parameters> <source_folder>`, which might overwrite the default settings.
2. `ld` issue (If building Ginkgo as static library, this is not needed)
* `cmake -DGINKGO_COMPILER_FLAGS="-Wpedantic -O1" <other parameters> <source_folder>` (`GINKGO_COMPILER_FLAGS` is `-Wpedantic` by default)
* add `-O1` in the environement variable `CXX_FLAGS` or `CMAKE_CXX_FLAGS`
* Possible issue when switching static/shared of Ginkgo with MSVC in the same build directory:\
If an issue occurs from mixing MD/MT runtime library when enabling `GINKGO_BUILD_BENCHMARKS`, it means the third-party flags are not updated correctly.
To update the third party flags, turn off `GINKGO_SKIP_DEPENDENCY_UPDATE` (`-DGINKGO_SKIP_DEPENDENCY_UPDATE=OFF`).
Some Debug build specific issues can appear depending on the machine and environment:
When you encounter the error message `ld: error: export ordinal too large`, add the compilation flag `-O1`
by adding `-DCMAKE_CXX_FLAGS=-O1` to the CMake invocation.
* Build Ginkgo in _MinGW_:\
If encountering the issue `cc1plus.exe: out of memory allocating 65536 bytes`, please follow the workaround in
[reference](https://www.intel.com/content/www/us/en/programmable/support/support-resources/knowledge-base/embedded/2016/cc1plus-exe--out-of-memory-allocating-65536-bytes.html),
Expand Down
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,10 @@ The Ginkgo CUDA module has the following __additional__ requirements:
The Ginkgo OMP module has the following __additional__ requirements:
* _MinGW_ or _Cygwin_

Depending on the configuration settings, some manual work might be required. More details are availble in [windows section in INSTALL.md](INSTALL.md#building-ginkgo-in-windows):
* Build Ginkgo as shared library:
Add `PROJECT_BINARY_DIR/GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH` into the environment variable `PATH`.
`GINKGO_WINDOWS_SHARED_LIBRARY_RELPATH` is `windows_shared_library` by default.
* Build Ginkgo with Debug mode:
Some Debug build specific issues can appear depending on the machine and environment. The known issues are the following:
1. `bigobj` issue: encountering `too many sections` needs the compilation flags `\bigobj` or `-Wa,-mbig-obj`
2. `ld` issue: encountering `ld: error: export ordinal too large` needs the compilation flag `-O1`
* Build Ginkgo in _MinGW_:
If encountering the issue `cc1plus.exe: out of memory allocating 65536 bytes`, please follow the workaround in
[reference](https://www.intel.com/content/www/us/en/programmable/support/support-resources/knowledge-base/embedded/2016/cc1plus-exe--out-of-memory-allocating-65536-bytes.html),
or compile ginkgo again might work.

__NOTE:__ _Microsoft Visual Studio_ only supports OpenMP 2.0, so it can not compile the ginkgo OMP module.
In these environments, two problems can be encountered, the solution for which is described in the
[windows section in INSTALL.md](INSTALL.md#building-ginkgo-in-windows):
* `ld: error: export ordinal too large` needs the compilation flag `-O1`
* `cc1plus.exe: out of memory allocating 65536 bytes` requires a modification of the environment

__NOTE:__ Some restrictions will also apply on the version of C and C++ standard
libraries installed on the system. This needs further investigation.
Expand Down
4 changes: 0 additions & 4 deletions cmake/GinkgoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ set(GINKGO_OPENMP_LIBRARIES @OpenMP_CXX_LIBRARIES@)

set(GINKGO_OPENMP_FLAGS "@OpenMP_CXX_FLAGS@")

if (WIN32 OR CYGWIN)
include(${CMAKE_CURRENT_LIST_DIR}/windows_helpers.cmake)
endif()

# NOTE: we do not export benchmarks, examples, tests or devel tools
# so `third_party` libraries are currently unneeded.

Expand Down
2 changes: 1 addition & 1 deletion cmake/autodetect_executors.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set(GINKGO_HAS_OMP OFF)
set(GINKGO_HAS_CUDA OFF)
set(GINKGO_HAS_DPCPP OFF)
set(GINKGO_HAS_HIP OFF)
find_package(OpenMP)
find_package(OpenMP 3.0)
include(CheckLanguage)
check_language(CUDA)
try_compile(GKO_CAN_COMPILE_DPCPP ${PROJECT_BINARY_DIR}/dpcpp
Expand Down
63 changes: 9 additions & 54 deletions cmake/build_helpers.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(GINKGO_LIBRARY_PATH "${PROJECT_BINARY_DIR}/lib")

function(ginkgo_default_includes name)
# set include path depending on used interface
target_include_directories("${name}"
Expand Down Expand Up @@ -26,26 +28,13 @@ function(ginkgo_compile_features name)
# Set an appropriate SONAME
set_property(TARGET "${name}" PROPERTY
SOVERSION "${Ginkgo_VERSION}")
if(GINKGO_CHANGED_SHARED_LIBRARY)
# Put all shared libraries and corresponding imported libraries into the specified path
set_property(TARGET "${name}" PROPERTY
RUNTIME_OUTPUT_DIRECTORY "${GINKGO_WINDOWS_SHARED_LIBRARY_PATH}")
set_property(TARGET "${name}" PROPERTY
ARCHIVE_OUTPUT_DIRECTORY "${GINKGO_WINDOWS_SHARED_LIBRARY_PATH}")
if(MSVC)
# MSVC would create subfolder according to build_type. Ginkgo forces the output be the same whatever build_type is.
foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${CONFIG} CONFIG )
set_property(TARGET "${name}" PROPERTY
RUNTIME_OUTPUT_DIRECTORY_${CONFIG} "${GINKGO_WINDOWS_SHARED_LIBRARY_PATH}")
set_property(TARGET "${name}" PROPERTY
ARCHIVE_OUTPUT_DIRECTORY_${CONFIG} "${GINKGO_WINDOWS_SHARED_LIBRARY_PATH}")
endforeach()
endif()
if(GINKGO_CHECK_PATH)
ginkgo_check_shared_library("${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()
endif()
# Put all shared libraries and corresponding imported libraries into the specified path
set_property(TARGET "${name}" PROPERTY
RUNTIME_OUTPUT_DIRECTORY "${GINKGO_LIBRARY_PATH}")
set_property(TARGET "${name}" PROPERTY
ARCHIVE_OUTPUT_DIRECTORY "${GINKGO_LIBRARY_PATH}")
set_property(TARGET "${name}" PROPERTY
LIBRARY_OUTPUT_DIRECTORY "${GINKGO_LIBRARY_PATH}")

if (GINKGO_CHECK_CIRCULAR_DEPS)
target_link_libraries("${name}" PRIVATE "${GINKGO_CIRCULAR_DEPS_FLAGS}")
Expand Down Expand Up @@ -104,40 +93,6 @@ function(ginkgo_check_headers target)
endif()
endfunction()

function(ginkgo_check_shared_library name)
# Cygwin uses : not ; to split path
if(CYGWIN)
string(REPLACE ":" ";" ENV_PATH "$ENV{PATH}")
else()
set(ENV_PATH "$ENV{PATH}")
endif()
set(PATH_LIST ${ENV_PATH})
set(PASSED_TEST FALSE)
foreach(ITEM IN LISTS PATH_LIST)
string(REPLACE "\\" "/" ITEM "${ITEM}")
if("${ITEM}" STREQUAL "${GINKGO_WINDOWS_SHARED_LIBRARY_PATH}")
set(PASSED_TEST TRUE)
break()
else()
# If any path before this build, the path must not contain the ginkgo shared library
find_file(EXISTING_DLL "${name}" PATHS "${ITEM}" NO_DEFAULT_PATH)
if(NOT "${EXISTING_DLL}" STREQUAL "EXISTING_DLL-NOTFOUND")
# clean the EXISTING_DLL before termination
unset(EXISTING_DLL CACHE)
message(FATAL_ERROR "Detect ${name} in ${ITEM} eariler than this build. "
"Please add ${GINKGO_WINDOWS_SHARED_LIBRARY_PATH} before other ginkgo path.")
endif()
# do not keep this variable in cache
unset(EXISTING_DLL CACHE)
endif()
endforeach()
if(NOT PASSED_TEST)
# Did not find this build in the environment variable PATH
message(FATAL_ERROR "Did not find this build in the environment variable PATH. "
"Please add ${GINKGO_WINDOWS_SHARED_LIBRARY_PATH} into the environment variable PATH.")
endif()
endfunction()

macro(ginkgo_modify_flags name)
# add escape before "
# the result var is ${name}_MODIFY
Expand Down
Loading