-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from scivision/main
CMake/CI: modernize and simplify
- Loading branch information
Showing
6 changed files
with
112 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,52 @@ | ||
name: Build | ||
name: Continuous | ||
|
||
on: [push] | ||
|
||
jobs: | ||
Continuous: | ||
name: ${{ matrix.name }} (${{ matrix.config }}) | ||
# 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: ${{ matrix.os }} | ||
|
||
linux-mac: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
config: [Release, Debug, RelWithDebInfo] | ||
include: | ||
- os: macos-latest | ||
name: macOS | ||
- os: ubuntu-latest | ||
name: Linux | ||
- os: windows-latest | ||
name: Windows | ||
cfg: [{os: ubuntu-latest, cxx: g++-12}, | ||
{os: ubuntu-latest, cxx: g++-9}, | ||
{os: macos-latest, cxx: clang++}] | ||
config: [Release, Debug] | ||
|
||
runs-on: ${{ matrix.cfg.os }} | ||
|
||
env: | ||
CXX: ${{ matrix.cfg.cxx }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Configure CMake | ||
run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.config }} -DSTLBFGS_UNIT_TESTS=ON | ||
|
||
- name: CMake Build | ||
run: cmake --build build --parallel | ||
|
||
- name: CTest | ||
run: ctest --test-dir build -V | ||
|
||
- name: Create Build Environment | ||
# Some projects don't allow in-source building, so create a separate build directory | ||
# We'll use this as our working directory for all subsequent commands | ||
run: cmake -E make_directory ${{github.workspace}}/build | ||
|
||
windows-msvc: | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Configure CMake | ||
# Use a bash shell so we can use the same syntax for environment variable | ||
# access regardless of the host operating system | ||
shell: bash | ||
working-directory: ${{github.workspace}}/build | ||
# Note the current convention is to use the -S and -B options here to specify source | ||
# and build directories, but this is only available with CMake 3.13 and higher. | ||
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12 | ||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.config }} -DSTLBFGS_UNIT_TESTS=ON | ||
|
||
- name: Build | ||
working-directory: ${{github.workspace}}/build | ||
shell: bash | ||
# Execute the build. You can specify a specific target with "--target <NAME>" | ||
run: cmake --build . --config ${{ matrix.config }} | ||
|
||
- name: Test | ||
working-directory: ${{github.workspace}}/build/tests | ||
shell: bash | ||
# Execute tests defined by the CMake configuration. | ||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | ||
run: ctest -C $BUILD_TYPE | ||
run: cmake -B build -DSTLBFGS_UNIT_TESTS=ON | ||
|
||
- name: Release build | ||
run: cmake --build build --parallel --config Release | ||
|
||
- name: Release CTest | ||
run: ctest --test-dir build -C Release -V | ||
|
||
- name: Debug build | ||
run: cmake --build build --parallel --config Debug | ||
|
||
- name: Debug CTest | ||
run: ctest --test-dir build -C Debug -V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
build | ||
*~ | ||
*.bak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,43 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(stlbfgs) | ||
cmake_minimum_required(VERSION 3.14...3.26) | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) | ||
if(NOT is_multi_config AND NOT (CMAKE_BUILD_TYPE OR DEFINED ENV{CMAKE_BUILD_TYPE})) | ||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Release default") | ||
endif() | ||
|
||
project(stlbfgs LANGUAGES CXX) | ||
|
||
enable_testing() | ||
|
||
option(STLBFGS_UNIT_TESTS "STLBFGS_UNIT_TESTS" OFF) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(OpenMP) | ||
if(OPENMP_FOUND) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") | ||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true) | ||
|
||
find_package(OpenMP COMPONENTS CXX) | ||
|
||
if(MSVC) | ||
add_compile_options(/W4) | ||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|Intel") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
set(RELATIVE_BIN_DIR bin/) | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${RELATIVE_BIN_DIR}/) | ||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
if (MSVC) | ||
# warning level 4 (and all warnings as errors, /WX) | ||
add_compile_options(/W4) | ||
else() | ||
# lots of warnings and all warnings as errors | ||
add_compile_options(-Wall -Wextra -pedantic) | ||
endif() | ||
|
||
add_library(stlbfgs linesearch.h stlbfgs.h linesearch.cpp stlbfgs.cpp) | ||
target_link_libraries(stlbfgs PRIVATE $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>) | ||
target_include_directories(stlbfgs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
set_property(TARGET stlbfgs PROPERTY SOVERSION 1.0) | ||
|
||
if(OpenMP_CXX_FOUND) | ||
target_link_libraries(stlbfgs OpenMP::OpenMP_CXX) | ||
endif() | ||
set_target_properties(stlbfgs PROPERTIES SOVERSION 1.0) | ||
|
||
option(STLBFGS_UNIT_TESTS "STLBFGS_UNIT_TESTS" OFF) | ||
if (STLBFGS_UNIT_TESTS) | ||
include(CTest) | ||
enable_testing() | ||
add_subdirectory(tests) | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
add_executable(stlbfgs-helloworld helloworld.cpp) | ||
target_link_libraries(stlbfgs-helloworld ${CMAKE_DL_LIBS} stlbfgs) | ||
if (NOT WIN32) | ||
target_link_libraries(stlbfgs-helloworld m) | ||
endif() | ||
target_link_libraries(stlbfgs-helloworld ${CMAKE_DL_LIBS} stlbfgs $<$<NOT:$<BOOL:${WIN32}>>:m>) | ||
|
||
file(GENERATE OUTPUT .gitignore CONTENT "*") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters