Skip to content

Commit

Permalink
Add CMake based build
Browse files Browse the repository at this point in the history
* Fix super build (e.g. FetchContent) integration
* cmake: option() honors normal variables (CMP0077)
* Add Test
  • Loading branch information
Mizux committed Dec 6, 2024
1 parent b5664c1 commit 7788d6b
Show file tree
Hide file tree
Showing 10 changed files with 1,053 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
aclocal.m4*
acinclude.m4
autom4te*
*.swp
.vs/
build/
cache/
143 changes: 143 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
cmake_minimum_required(VERSION 3.16)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(ParseAc)
parse_ac(VERSION MAJOR MINOR PATCH)

project(Clp VERSION ${VERSION} LANGUAGES CXX C)
set(PROJECT_NAMESPACE coin)
message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}")
#message(STATUS "major: ${PROJECT_VERSION_MAJOR}")
#message(STATUS "minor: ${PROJECT_VERSION_MINOR}")
#message(STATUS "patch: ${PROJECT_VERSION_PATCH}")

# Default Build Type to be Release
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig)
if(NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING
"Choose the type of builds, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release;Debug)"
FORCE)
endif()
message(STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
else()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release)"
FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
endif()

# Layout build dir like install dir
include(GNUInstallDirs)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
if(UNIX)
option(BUILD_SHARED_LIBS "Build shared libraries (.so or .dylib)." ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
# for multi-config build system (e.g. Xcode, Ninja Multi-Config)
foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${OutputConfig} OUTPUTCONFIG)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
endforeach()
else()
# Currently Only support static build for windows
option(BUILD_SHARED_LIBS "Build shared libraries (.dll)." OFF)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
# for multi-config builds (e.g. msvc)
foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${OutputConfig} OUTPUTCONFIG)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR})
endforeach()
endif()

if(MSVC AND BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

# config options
if(MSVC)
# Build with multiple processes
add_definitions(/MP)
add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE)
# MSVC warning suppressions
add_definitions(
/wd4018 # 'expression' : signed/unsigned mismatch
/wd4065 # switch statement contains 'default' but no 'case' labels
/wd4101 # 'identifier' : unreferenced local variable
/wd4102 # 'label' : unreferenced label
/wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
/wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
/wd4309 # 'conversion' : truncation of constant value
/wd4805 # 'operation' : unsafe mix of type 'type1' and type 'type2' in operation.
/wd4996 # The compiler encountered a deprecated declaration.
)
endif()
if(APPLE)
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override -Wno-unused-command-line-argument -Wno-unused-result -Wno-exceptions"
)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
endif()

# ZLIB
if(NOT TARGET ZLIB::ZLIB)
find_package(ZLIB)
endif()
if(ZLIB_FOUND OR TARGET ZLIB::ZLIB)
message(STATUS "Use zlib")
set(HAVE_ZLIB_H "1" CACHE INTERNAL "Use zlib")
set(COIN_HAS_ZLIB "1" CACHE INTERNAL "Use zlib")
endif()

# PThread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
if(CMAKE_USE_PTHREADS_INIT)
set(PTHREADS_FOUND TRUE)
else()
set(PTHREADS_FOUND FALSE)
endif()

# CoinUtils
if(NOT TARGET Coin::CoinUtils)
find_package(CoinUtils REQUIRED CONFIG)
endif()
# Osi
if(NOT TARGET Coin::Osi)
find_package(Osi REQUIRED CONFIG)
endif()

include(CheckEnv)
include(CTest)

add_subdirectory(Clp)

include(GNUInstallDirs)
install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE Coin::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/Config.cmake.in
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion)
install(
FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
COMPONENT Devel)
Loading

0 comments on commit 7788d6b

Please sign in to comment.