Skip to content

Commit

Permalink
Merge pull request #38 from imciner2/im/disabletargets
Browse files Browse the repository at this point in the history
  • Loading branch information
imciner2 authored Oct 8, 2021
2 parents c662639 + 9fae555 commit f2665f8
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 82 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Configure
shell: bash
working-directory: ${{ runner.workspace }}/build
run: cmake --warn-uninitialized -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUNITTESTS=ON -DCOVERAGE=${{ matrix.coverage }} $GITHUB_WORKSPACE
run: cmake --warn-uninitialized -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DQDLDL_UNITTESTS=ON -DCOVERAGE=${{ matrix.coverage }} $GITHUB_WORKSPACE

- name: Build
shell: bash
Expand Down Expand Up @@ -69,11 +69,13 @@ jobs:
matrix:
float: [ON, OFF]
long: [ON, OFF]
static: [ON, OFF]
shared: [ON, OFF]

# Only test the build configs on Linux
runs-on: ubuntu-latest

name: Config - FLOAT=${{ matrix.float }}, LONG=${{ matrix.long }}
name: Config - FLOAT=${{ matrix.float }}, LONG=${{ matrix.long }}, SHARED=${{ matrix.shared }}, STATIC=${{ matrix.static }}

steps:
- name: Check out repository
Expand All @@ -87,14 +89,16 @@ jobs:
- name: Configure
shell: bash
working-directory: ${{ runner.workspace }}/build
run: cmake --warn-uninitialized -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DDFLOAT=${{ matrix.float }} -DDLONG=${{ matrix.long }} -DUNITTESTS=ON -DCOVERAGE=OFF $GITHUB_WORKSPACE
run: cmake --warn-uninitialized -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DQDLDL_BUILD_SHARED_LIB=${{ matrix.shared }} -DQDLDL_BUILD_STATIC_LIB=${{ matrix.static }} -DDFLOAT=${{ matrix.float }} -DDLONG=${{ matrix.long }} -DQDLDL_UNITTESTS=ON -DCOVERAGE=OFF $GITHUB_WORKSPACE

- name: Build
shell: bash
working-directory: ${{ runner.workspace }}/build
run: cmake --build . --config $BUILD_TYPE

# The test suite requires the static library for linkage
- name: Run tests
if: ${{ matrix.static == 'ON' }}
shell: bash
working-directory: ${{ runner.workspace }}/build
run: ctest -C $BUILD_TYPE
183 changes: 106 additions & 77 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ set(QDLDL_VERSION "${QDLDL_VERSION_MAJOR}.${QDLDL_VERSION_MINOR}.${QDLDL_VERSION
# Project name
project(qdldl VERSION ${QDLDL_VERSION})

include( CMakeDependentOption )

option( QDLDL_BUILD_STATIC_LIB "Build the static library" ON )
option( QDLDL_BUILD_SHARED_LIB "Build the shared library" ON )

cmake_dependent_option( QDLDL_BUILD_DEMO_EXE
"Build the demo executable (requires the static library)"
ON # Default to on
QDLDL_BUILD_STATIC_LIB OFF ) # Force off if the static library isn't built

cmake_dependent_option( QDLDL_UNITTESTS
"Build the unit testing suite"
OFF # Default to off
QDLDL_BUILD_STATIC_LIB OFF ) # Force off if the static library isn't built

# Set the output folder where your program will be created
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/out)
Expand All @@ -23,12 +37,13 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Options
# ----------------------------------------------
# Use floats instead of doubles
set(DFLOAT OFF CACHE BOOL "Use float numbers instead of doubles")
option( DFLOAT "Use float numbers instead of doubles" OFF )
message(STATUS "Floats are ${DFLOAT}")

# Use long integers for indexing
set(DLONG ON CACHE BOOL "Use long integers (64bit) for indexing")
if (NOT (CMAKE_SIZEOF_VOID_P EQUAL 8))
option( DLONG "Use long integers (64bit) for indexing" ON )

if( NOT (CMAKE_SIZEOF_VOID_P EQUAL 8) )
message(STATUS "Disabling long integers (64bit) on 32bit machine")
set(DLONG OFF)
endif()
Expand All @@ -45,9 +60,10 @@ if (NOT MSVC)

if (COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
if(FORTRAN)
set(CMAKE_FORTRAN_FLAGS "${CMAKE_FORTRAN_FLAGS} --coverage")
endif(FORTRAN)

if(FORTRAN)
set(CMAKE_FORTRAN_FLAGS "${CMAKE_FORTRAN_FLAGS} --coverage")
endif(FORTRAN)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
Expand All @@ -60,15 +76,15 @@ endif (NOT MSVC)
# numeric types
if(DFLOAT)
set(QDLDL_FLOAT_TYPE "float")
set(QDLDL_DFLOAT 1)
set(QDLDL_FLOAT 1)
else()
set(QDLDL_FLOAT_TYPE "double")
endif()

if(DLONG)
set(QDLDL_INT_TYPE "long long")
set(QDLDL_INT_TYPE_MAX "LLONG_MAX")
set(QDLDL_DLONG 1)
set(QDLDL_LONG 1)
else()
set(QDLDL_INT_TYPE "int")
set(QDLDL_INT_TYPE_MAX "INT_MAX")
Expand Down Expand Up @@ -116,25 +132,28 @@ target_include_directories(qdldlobject PRIVATE ${PROJECT_SOURCE_DIR}/include)

include(GNUInstallDirs)

# Static library
add_library (qdldlstatic STATIC ${qdldl_src} ${qdldl_headers})
# Give same name to static library output
set_target_properties(qdldlstatic PROPERTIES OUTPUT_NAME qdldl)
message( STATUS "Static library build is ${QDLDL_BUILD_STATIC_LIB}" )

# Declare include directories for the cmake exported target
target_include_directories(qdldlstatic
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/qdldl>")
if( QDLDL_BUILD_STATIC_LIB )
# Static library
add_library (qdldlstatic STATIC ${qdldl_src} ${qdldl_headers})
# Give same name to static library output
set_target_properties(qdldlstatic PROPERTIES OUTPUT_NAME qdldl)

# Install Static Library
# ----------------------------------------------
# Declare include directories for the cmake exported target
target_include_directories(qdldlstatic
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/qdldl>")

install(TARGETS qdldlstatic
EXPORT ${PROJECT_NAME}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
# Install Static Library
# ----------------------------------------------

install(TARGETS qdldlstatic
EXPORT ${PROJECT_NAME}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()

# Install Headers
# ----------------------------------------------
Expand All @@ -144,85 +163,95 @@ install(FILES ${qdldl_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qdldl")
# Install Shared Library
# ----------------------------------------------
# Create qdldl shared library
add_library (qdldl SHARED ${qdldl_src} ${qdldl_headers})
message( STATUS "Shared library build is ${QDLDL_BUILD_SHARED_LIB}" )

# Declare that we are building the shared library to get proper symbol exports.
# Shared library consumers should also define QDLDL_SHARED_LIB to get the library
# exports properly, so we do it for them in the CMake interface by defining it as
# a PUBLIC compile definition.
target_compile_definitions(qdldl PRIVATE BUILDING_QDLDL)
target_compile_definitions(qdldl PUBLIC QDLDL_SHARED_LIB)
if( QDLDL_BUILD_SHARED_LIB )
add_library (qdldl SHARED ${qdldl_src} ${qdldl_headers})

# Declare include directories for the cmake exported target
target_include_directories(qdldl
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/qdldl>")
# Declare that we are building the shared library to get proper symbol exports.
# Shared library consumers should also define QDLDL_SHARED_LIB to get the library
# exports properly, so we do it for them in the CMake interface by defining it as
# a PUBLIC compile definition.
target_compile_definitions(qdldl PRIVATE BUILDING_QDLDL)
target_compile_definitions(qdldl PUBLIC QDLDL_SHARED_LIB)

# Install qdldl shared library
install(TARGETS qdldl
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
# Declare include directories for the cmake exported target
target_include_directories(qdldl
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/qdldl>")

# Create demo executable (linked to static library)
add_executable (qdldl_example ${PROJECT_SOURCE_DIR}/examples/example.c)
target_link_libraries (qdldl_example qdldlstatic)
# Install qdldl shared library
install(TARGETS qdldl
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()


message( STATUS "Demo executable build is ${QDLDL_BUILD_DEMO_EXE}" )

if( QDLDL_BUILD_DEMO_EXE )
# Create demo executable (linked to static library)
add_executable (qdldl_example ${PROJECT_SOURCE_DIR}/examples/example.c)
target_link_libraries (qdldl_example qdldlstatic)
else()
message( STATUS "Not building demo executable" )
endif()

# Create CMake packages for the build directory
# ----------------------------------------------
include(CMakePackageConfigHelpers)
if( QDLDL_BUILD_SHARED_LIB OR QDLDL_BUILD_STATIC_LIB)
include(CMakePackageConfigHelpers)

write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/qdldl-config-version.cmake"
VERSION ${QDLDL_VERSION}
COMPATIBILITY SameMajorVersion
)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/qdldl-config-version.cmake"
VERSION ${QDLDL_VERSION}
COMPATIBILITY SameMajorVersion
)

export(EXPORT ${PROJECT_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/qdldl-targets.cmake"
NAMESPACE qdldl::)

if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/qdldl-config.cmake)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/qdldl-config.cmake "include(\"\${CMAKE_CURRENT_LIST_DIR}/qdldl-targets.cmake\")\n")
endif()
export(EXPORT ${PROJECT_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/qdldl-targets.cmake"
NAMESPACE qdldl::)

if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/qdldl-config.cmake)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/qdldl-config.cmake "include(\"\${CMAKE_CURRENT_LIST_DIR}/qdldl-targets.cmake\")\n")
endif()

# Create CMake packages for the install directory
# ----------------------------------------------

set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/qdldl)
# Create CMake packages for the install directory
# ----------------------------------------------

install(EXPORT ${PROJECT_NAME}
FILE qdldl-targets.cmake
NAMESPACE qdldl::
DESTINATION ${ConfigPackageLocation})
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/qdldl)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qdldl-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/qdldl-config-version.cmake
DESTINATION ${ConfigPackageLocation})
install(EXPORT ${PROJECT_NAME}
FILE qdldl-targets.cmake
NAMESPACE qdldl::
DESTINATION ${ConfigPackageLocation})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qdldl-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/qdldl-config-version.cmake
DESTINATION ${ConfigPackageLocation})

# Add uninstall command
# ----------------------------------------------
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/configure/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

# Add uninstall command
# ----------------------------------------------
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/configure/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
endif()



# Add testing
# ----------------------------------------------
# Add custom command to generate tests
if (UNITTESTS)
message( STATUS "Unit testing suite build is ${QDLDL_UNITTESTS}" )

if( QDLDL_UNITTESTS )
# Add test_headers and codegen_test_headers
add_subdirectory(tests)

Expand Down
4 changes: 2 additions & 2 deletions configure/qdldl_types.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ typedef @QDLDL_BOOL_TYPE@ QDLDL_bool; /* for boolean values */
*/

/* When defined, QDLDL is using floats instead of doubles */
#cmakedefine QDLDL_DFLOAT
#cmakedefine QDLDL_FLOAT

/* When defined, QDLDL is using long long instead of int types */
#cmakedefine QDLDL_DLONG
#cmakedefine QDLDL_LONG

# ifdef __cplusplus
}
Expand Down

0 comments on commit f2665f8

Please sign in to comment.