Commit 1023a453 authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Add options to factorize lib and include path in CMAKE_..._PATH variables

parent d2eecd20
......@@ -35,6 +35,8 @@ option(MORSE_ENABLE_WARNING "Enable warning messages from the compiler"
option(MORSE_ENABLE_STATIC_ANALYSIS "Enable warning messages from external static analyzers such as cppcheck " OFF)
option(MORSE_ENABLE_COVERAGE "Enable flags for coverage test" OFF)
option(MORSE_ENABLE_COLOR_MESSAGE "Enable colors in messages" OFF)
option(MORSE_ENABLE_ENV_INCLUDE "Enable the use of INCLUDE, INCLUDE_PATH to populate CMAKE_INCLUDE_PATH in that order" ON)
option(MORSE_ENABLE_ENV_LIBRARY "Enable the use of LIBRARY_PATH, LD_LIBRARY_PATH to populate CMAKE_LIBRARY_PATH in that order" ON)
#option(MORSE_VERBOSE_FIND_PACKAGE "Add additional messages concerning packages not found" OFF)
#message(STATUS "MORSE_VERBOSE_FIND_PACKAGE is set to OFF, turn it ON to get"
# " information about packages not found")
......@@ -71,6 +73,43 @@ if(NOT CMAKE_BUILD_TYPE)
endif(NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_BUILD_TYPE_DROP_LIST})
if ( MORSE_ENABLE_ENV_LIBRARY )
set(_libdir "$ENV{LIBRARY_PATH}")
if (WIN32)
set(_libdir "${_libdir}:$ENV{LIB}")
elseif (APPLE)
set(_libdir "${_libdir}:$ENV{DYLD_LIBRARY_PATH}")
else ()
set(_libdir "${_libdir}:$ENV{LD_LIBRARY_PATH}")
endif ()
string(REPLACE ":" ";" _libdir "${_libdir}")
string(REPLACE ";;" ";" _libdir "${_libdir}")
list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
list(REMOVE_DUPLICATES _libdir)
list(APPEND CMAKE_LIBRARY_PATH "${_libdir}" )
endif()
if ( MORSE_ENABLE_ENV_INCLUDE )
if(WIN32)
set( _incdir "$ENV{INCLUDE}" )
else()
set( _incdir "$ENV{INCLUDE}:" )
set( _incdir "${_incdir}:$ENV{C_INCLUDE_PATH}" )
set( _incdir "${_incdir}:$ENV{CPATH}" )
set( _incdir "${_incdir}:$ENV{INCLUDE_PATH}" )
endif()
string( REPLACE ":" ";" _incdir "${_incdir}" )
string( REPLACE ";;" ";" _incdir "${_incdir}" )
list(APPEND _incdir "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
list(REMOVE_DUPLICATES _incdir)
list(APPEND CMAKE_INCLUDE_PATH "${_incdir}" )
endif()
##
## @end file MorseInit.cmake
##
......@@ -184,16 +184,6 @@ endmacro()
# e.g. for pkg_search_module(BLAS blas) _prefix would be BLAS
macro(morse_find_pkgconfig_libraries_absolute_path _prefix)
set(_lib_env ENV LIBRARY_PATH)
if (WIN32)
list(APPEND _lib_env ENV LIB)
elseif (APPLE)
list(APPEND _lib_env ENV DYLD_LIBRARY_PATH)
else ()
list(APPEND _lib_env ENV LD_LIBRARY_PATH)
endif ()
list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
set(${_prefix}_LIBRARIES_COPY "${${_prefix}_LIBRARIES}")
set(${_prefix}_LIBRARIES "")
foreach(_library ${${_prefix}_LIBRARIES_COPY})
......@@ -226,7 +216,7 @@ macro(morse_find_pkgconfig_libraries_absolute_path _prefix)
find_library( _library_path
NAMES ${_library}
HINTS ${${_prefix}_LIBDIR} ${${_prefix}_LIBRARY_DIRS} ${_lib_env}
HINTS ${${_prefix}_LIBDIR} ${${_prefix}_LIBRARY_DIRS}
)
if (_library_path)
......
......@@ -26,18 +26,6 @@ cmake_minimum_required(VERSION 3.3)
# hints_paths (input): additional paths to add when looking for libraries
macro(LIBRARIES_ABSOLUTE_PATH lib_list hints_paths)
# collect environment paths to dig
# Should not need to do that
set(_lib_env ENV LIBRARY_PATH)
if (WIN32)
list(APPEND _lib_env ENV LIB)
elseif (APPLE)
list(APPEND _lib_env ENV DYLD_LIBRARY_PATH)
else ()
list(APPEND _lib_env ENV LD_LIBRARY_PATH)
endif ()
list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
# copy the lib list
set (${lib_list}_COPY "${${lib_list}}")
......@@ -63,7 +51,7 @@ macro(LIBRARIES_ABSOLUTE_PATH lib_list hints_paths)
# try to find the lib
find_library(_library_path
NAMES ${_library}
HINTS ${hints_paths} ${_lib_env}
HINTS ${hints_paths}
)
if (_library_path)
list(APPEND ${lib_list} ${_library_path})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment