diff --git a/.github/workflows/continuous.yml b/.github/workflows/continuous.yml index 037229b..774d09e 100644 --- a/.github/workflows/continuous.yml +++ b/.github/workflows/continuous.yml @@ -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 " - 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 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index e0cfa4f..162e340 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -5,52 +5,43 @@ on: - cron: '0 4 * * *' 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 + core: runs-on: ${{ matrix.os }} 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 + os: [ubuntu-latest, macos-latest] + config: [Release, Debug] + 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 " - 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 diff --git a/.gitignore b/.gitignore index e151175..e7683df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -build *~ *.bak diff --git a/CMakeLists.txt b/CMakeLists.txt index 8360c09..b7fb221 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 $<$: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 $<$>:m>) +file(GENERATE OUTPUT .gitignore CONTENT "*") diff --git a/README.md b/README.md index e21b4cf..a0a5d09 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,11 @@ int main() { # Build and run unit tests: ```sh -git clone https://github.com/ssloy/stlbfgs.git && -cd stlbfgs && -mkdir build && -cd build && -cmake -DSTLBFGS_UNIT_TESTS:BOOL=ON .. && -cmake --build . -j && -cd tests && -ctest +git clone https://github.com/ssloy/stlbfgs.git +cd stlbfgs +cmake -B build -DSTLBFGS_UNIT_TESTS:BOOL=ON +cmake --build build -j +ctest --test-dir build -V ``` # References @@ -57,4 +54,3 @@ ctest **[5]** Gilbert JC, Lemaréchal C. The module M1QN3. INRIA Rep., version. 2006;3:21. **[6]** Gilbert JC, Lemaréchal C. Some numerical experiments with variable-storage quasi-Newton algorithms. Mathematical Programming 45, pp. 407-435, 1989. - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 76b5b72..d5a82d6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,15 @@ -cmake_minimum_required(VERSION 3.14 FATAL_ERROR) - Include(FetchContent) + +set(FETCHCONTENT_QUIET false) + FetchContent_Declare( Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.3.1) + GIT_TAG v3.3.1 + GIT_SHALLOW true + TLS_VERIFY ON + INACTIVITY_TIMEOUT 60 + ) FetchContent_MakeAvailable(Catch2) @@ -16,4 +21,3 @@ target_link_libraries(stlbfgs-test-all PRIVATE ${CMAKE_DL_LIBS} stlbfgs Catch2:: include(Catch) catch_discover_tests(stlbfgs-test-all) -