Hello everyone.
I am trying to create a FindAMPL.cmake
script, but I am having some problems, In this link I share the first version. Bellow follows my FindAMPL.cmake
:
if (AMPL_LIBRARY)
SET(AMPL_FIND_QUIETLY TRUE)
endif (AMPL_LIBRARY)
IF ( UNIX )
# target not already created
if (NOT TARGET ampl)
# ampl dir
find_path(AMPL_DIR NAMES "ampl"
PATHS
"/opt/ampl/"
"/opt/AMPL/"
"~/ampl/"
"~/AMPL/"
)
# edge case
IF( NOT AMPL_FIND_QUIETLY AND NOT AMPL_DIR)
message ( "AMPL_DIR not found ")
ENDIF()
# amplapi
set(AMPL_API_DIR "${AMPL_DIR}/amplapi")
# runpath
set(CMAKE_INSTALL_RPATH "${AMPL_API_DIR}/lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# lib
set(AMPL_LIBRARY_NAME "ampl")
add_library(ampl STATIC IMPORTED)
find_library(AMPL_LIBRARY ${AMPL_LIBRARY_NAME} PATHS ${CMAKE_INSTALL_RPATH})
# edge case
if(NOT(AMPL_LIBRARY))
message(FATAL_ERROR "AMPL library \"${AMPL_LIBRARY_NAME}\" could not be found")
endif()
set_target_properties(ampl PROPERTIES
IMPORTED_LOCATION ${AMPL_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${AMPL_API_DIR}/include)
endif ()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBAMPL_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(AMPL DEFAULT_MSG AMPL_LIBRARY)
mark_as_advanced(AMPL_LIBRARY)
ENDIF()
And below follows my CMakeLists.txt
:
cmake_minimum_required(VERSION 3.16)
project(AMPLCMake)
##### SETs
set (Project_PATH "${PROJECT_SOURCE_DIR}")
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/support)
set (CMAKE_BUILD_TYPE Release)
set (CMAKE_CXX_STANDARD 20)
set (BUILD_SHARED_LIBS On)
##### Includes
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
conan_basic_setup()
##### Additional packages
find_package (AMPL)
##### Include Dirs
include_directories(
SYSTEM
includes
"${PROJECT_BINARY_DIR}"
"${AMPL_LIBRARY}"
)
##### Compile options
add_compile_options(-Wall
-DIL_STD
-Wfatal-errors
-pedantic
-fopenmp
-DDEBUG
-fdiagnostics-color=always
-lz
-std=c++20
-lm
#
-lpthread
-ldl
-Wno-sign-compare
)
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(
main
${SOURCES}
${AMPL_LIBRARY}
)
target_link_libraries(
main
${AMPL_LIBRARY}
ampl
pthread
m
dl
)
The conan install ..
and the cmake ..
commands work just fine. But the make
returns this:
cc1plus: warning: ~/ampl/amplapi/lib/libampl.so: not a directory
In file included from ~/ampl/amplapi/include/ampl/amplexception.h:8,
from ~/ampl/amplapi/include/ampl/ep/errorinfo_ep.h:6,
from ~/ampl/amplapi/include/ampl/variant.h:7,
from ~/ampl/amplapi/include/ampl/ep/arg.h:4,
from ~/ampl/amplapi/include/ampl/dataframe.h:4,
from ~/ampl/amplapi/include/ampl/ampl.h:4,
from ~/ampl_test/src/main.cpp:3:
~/ampl/amplapi/include/ampl/format.h: In instantiation of ‘void fmt::internal::MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t) [with T = wchar_t; long unsigned int SIZE = 500; Allocator = std::allocator<wchar_t>; std::size_t = long unsigned int]’:
~/ampl/amplapi/include/ampl/format.h:799:6: required from here
~/ampl/amplapi/include/ampl/format.h:802:30: error: no matching function for call to ‘fmt::internal::MemoryBuffer<wchar_t, 500, std::allocator<wchar_t> >::allocate(std::size_t&, std::nullptr_t)’
802 | T *new_ptr = this->allocate(new_capacity, FMT_NULL);
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
make[2]: *** [CMakeFiles/main.dir/build.make:76: CMakeFiles/main.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
AnNd yes, the directory ~/ampl/amplapi/lib/libampl.so
exists, although I do not know why CMake relutes in recognizing it.
I would like to know if anyone ever passed by such situation before.
Thanks and best regards.