Skip to content

Commit

Permalink
Check minimum CppAD version
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoleal committed Feb 6, 2020
1 parent d2bd4b1 commit 8f33df8
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# ----------------------------------------------------------------------------
FIND_PACKAGE(Threads REQUIRED)

FIND_PACKAGE(CppAD REQUIRED)
FIND_PACKAGE(CppAD 20200000.1 REQUIRED)

FIND_PACKAGE(ADOLC)

Expand Down
2 changes: 1 addition & 1 deletion cmake/FindADOLC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ENDIF( PKG_CONFIG_FOUND )

IF( ADOLC_FOUND )
IF(NOT ADOLC_FIND_QUIETLY)
MESSAGE(STATUS "package adolc>=2.3 found")
MESSAGE(STATUS "package adolc ${ADOLC_VERSION} found")
ENDIF()
ELSE( ADOLC_FOUND )
FIND_PATH(ADOLC_INCLUDE_DIRS NAMES adouble.h
Expand Down
100 changes: 60 additions & 40 deletions cmake/FindCppAD.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ----------------------------------------------------------------------------
# CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
# Copyright (C) 2012 Ciengis
# Copyright (C) 2020 Joao Leal
#
# CppADCodeGen is distributed under multiple licenses:
#
Expand All @@ -19,64 +20,83 @@
# CPPAD_LIBRARIES - The libraries needed to use CppAD

IF (CPPAD_INCLUDES AND CPPAD_LIBRARIES)
SET(CPPAD_FIND_QUIETLY TRUE)
SET(CPPAD_FIND_QUIETLY TRUE)
ENDIF ()


IF(DEFINED CPPAD_HOME)
IF (DEFINED CPPAD_HOME)

FIND_PATH(CPPAD_INCLUDE_DIR NAMES cppad/cppad.hpp
PATHS "${CPPAD_HOME}"
FIND_PATH(CPPAD_INCLUDE_DIR NAMES cppad/cppad.hpp
PATHS "${CPPAD_HOME}"
NO_DEFAULT_PATH)

FIND_LIBRARY(CPPAD_IPOPT_LIBRARY
cppad_ipopt
PATHS "${CPPAD_HOME}/lib"
NO_DEFAULT_PATH)

FIND_LIBRARY(CPPAD_IPOPT_LIBRARY
cppad_ipopt
PATHS "${CPPAD_HOME}/lib"
NO_DEFAULT_PATH)
SET(CPPAD_INCLUDE_DIRS ${CPPAD_INCLUDE_DIR})
SET(CPPAD_LIBRARIES ${CPPAD_IPOPT_LIBRARY})
SET(CPPAD_FOUND TRUE)

SET(CPPAD_INCLUDE_DIRS ${CPPAD_INCLUDE_DIR})
SET(CPPAD_LIBRARIES ${CPPAD_IPOPT_LIBRARY})
ELSE ()

ELSE()
FIND_PACKAGE(PkgConfig)

FIND_PACKAGE(PkgConfig)
IF (PKG_CONFIG_FOUND)
pkg_check_modules(CPPAD QUIET cppad>=${CppAD_FIND_VERSION})
ENDIF ()

IF( PKG_CONFIG_FOUND )
pkg_check_modules( CPPAD QUIET cppad)
ENDIF()

IF (NOT CPPAD_FOUND)

IF( NOT CPPAD_FOUND )
FIND_PATH(CPPAD_INCLUDE_DIR NAMES cppad/cppad.hpp
HINTS "$ENV{CPPAD_HOME}"
"/usr/include" )
FIND_PATH(CPPAD_INCLUDE_DIR NAMES cppad/cppad.hpp
HINTS "$ENV{CPPAD_HOME}"
"/usr/include")

FIND_LIBRARY(CPPAD_IPOPT_LIBRARY
cppad_ipopt
HINTS "$ENV{CPPAD_HOME}/lib"
"/usr/lib" )
FIND_LIBRARY(CPPAD_IPOPT_LIBRARY
cppad_ipopt
HINTS "$ENV{CPPAD_HOME}/lib"
"/usr/lib")

IF( CPPAD_INCLUDE_DIR )
SET(CPPAD_INCLUDE_DIRS ${CPPAD_INCLUDE_DIR})
ENDIF()
IF (CPPAD_INCLUDE_DIR)
SET(CPPAD_INCLUDE_DIRS ${CPPAD_INCLUDE_DIR})
ENDIF ()

IF( CPPAD_IPOPT_LIBRARY )
SET(CPPAD_LIBRARIES ${CPPAD_IPOPT_LIBRARY})
ENDIF()
IF (CPPAD_IPOPT_LIBRARY)
SET(CPPAD_LIBRARIES ${CPPAD_IPOPT_LIBRARY})
ENDIF ()

INCLUDE(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set CPPAD_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(CppAD DEFAULT_MSG
CPPAD_INCLUDE_DIRS)
INCLUDE(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set CPPAD_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(CppAD DEFAULT_MSG
CPPAD_INCLUDE_DIRS)

MARK_AS_ADVANCED(CPPAD_INCLUDE_DIRS CPPAD_LIBRARIES)
MARK_AS_ADVANCED(CPPAD_INCLUDE_DIRS CPPAD_LIBRARIES)

ENDIF()
ENDIF()
ENDIF ()
ENDIF ()

IF (CPPAD_FOUND)

IF (CppAD_FIND_VERSION)

IF (NOT CPPAD_VERSION)
FILE(STRINGS ${CPPAD_INCLUDE_DIR}/cppad/configure.hpp CPPAD_VERSION_LINE
REGEX "CPPAD_PACKAGE_STRING +\"cppad-[0-9]+\\.[0-9]+\"")
STRING(REGEX MATCH "[0-9]+\\.[0-9]+" CPPAD_VERSION "${CPPAD_VERSION_LINE}")
ENDIF ()

IF( CPPAD_FOUND AND NOT CPPAD_FIND_QUIETLY )
MESSAGE(STATUS "package CppAD found")
ENDIF()
IF ("${CPPAD_VERSION}" VERSION_LESS "${CppAD_FIND_VERSION}")
SET(CPPAD_FOUND FALSE)
message(FATAL_ERROR "Found CppAD version '${CPPAD_VERSION}' but at least version '${CppAD_FIND_VERSION}' is required")
ENDIF ()
ENDIF ()

IF (CPPAD_FOUND AND NOT CPPAD_FIND_QUIETLY)
MESSAGE(STATUS "package CppAD ${CPPAD_VERSION} found")
ENDIF ()

ENDIF ()

10 changes: 10 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# --------------------------------------------------------------------------
# CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
# Copyright (C) 2012 Ciengis
# Copyright (C) 2020 Joao Leal
#
# CppADCodeGen is distributed under multiple licenses:
#
Expand All @@ -13,9 +14,18 @@
#
# Author: Joao Leal
#

CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/cppad/cg/configure.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/cppad/cg/configure.hpp
)
INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/cppad/cg/configure.hpp
DESTINATION "${install_cppadcg_include_location}/cg")

# ----------------------------------------------------------------------------
# files to be installed
# ----------------------------------------------------------------------------

INSTALL( DIRECTORY "cppad/cg/"
DESTINATION "${install_cppadcg_include_location}/cg"
FILES_MATCHING PATTERN "*.hpp")
Expand Down
20 changes: 20 additions & 0 deletions include/cppad/cg/configure.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef CPPAD_CG_CONFIGURE_INCLUDED
#define CPPAD_CG_CONFIGURE_INCLUDED
/* --------------------------------------------------------------------------
* CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
* Copyright (C) 2020 Joao Leal
*
* CppADCodeGen is distributed under multiple licenses:
*
* - Eclipse Public License Version 1.0 (EPL1), and
* - GNU General Public License Version 3 (GPL3).
*
* EPL1 terms and conditions can be found in the file "epl-v10.txt", while
* terms and conditions for the GPL3 can be found in the file "gpl3.txt".
* ----------------------------------------------------------------------------
* Author: Joao Leal
*/

#define CPPAD_CG_VERSION "cppadcg-@cppadcg_version@"

#endif
3 changes: 2 additions & 1 deletion pkgconfig/cppadcg.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# CppADCodeGen: C++ Algorithmic Differentiation with source code generation
#
# Copyright (C) 2012 Ciengis
# Copyright (C) 2020 Joao Leal
#
# CppAD is distributed under multiple licenses. This distribution is under
# the terms of the
Expand All @@ -16,4 +17,4 @@ Description: @cppadcg_description@
Version: @cppadcg_version@
URL: @cppadcg_url@
Cflags: -I@install_cppadcg_include_pkg_location@ -I@install_cppad_include_pkg_location@
Requires: cppad >= 20150302
Requires: cppad >= @cppad_version_min@

0 comments on commit 8f33df8

Please sign in to comment.