Skip to content

Commit e22bbdb

Browse files
committed
Add CMake-based build system
1 parent 164afbe commit e22bbdb

8 files changed

+598
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.swp
2+
.vs/
3+
build/
4+
cache/

CMakeLists.txt

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
3+
4+
include(ParseAc)
5+
parse_ac(VERSION MAJOR MINOR PATCH)
6+
7+
project(CoinUtils VERSION ${VERSION})
8+
9+
# config options
10+
if(NOT CMAKE_BUILD_TYPE)
11+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
12+
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
13+
FORCE)
14+
endif(NOT CMAKE_BUILD_TYPE)
15+
16+
option(BUILD_SHARED_LIBS "" ON)
17+
if(BUILD_SHARED_LIBS AND MSVC)
18+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
19+
endif(BUILD_SHARED_LIBS AND MSVC)
20+
21+
# config options
22+
if(MSVC)
23+
# Build with multiple processes
24+
add_definitions(/MP)
25+
add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE)
26+
# MSVC warning suppressions
27+
add_definitions(
28+
/wd4018 # 'expression' : signed/unsigned mismatch
29+
/wd4065 # switch statement contains 'default' but no 'case' labels
30+
/wd4101 # 'identifier' : unreferenced local variable
31+
/wd4102 # 'label' : unreferenced label
32+
/wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
33+
/wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
34+
/wd4309 # 'conversion' : truncation of constant value
35+
/wd4805 # 'operation' : unsafe mix of type 'type1' and type 'type2' in operation.
36+
/wd4996 # The compiler encountered a deprecated declaration.
37+
)
38+
endif()
39+
if(APPLE)
40+
set(
41+
CMAKE_CXX_FLAGS
42+
"${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override -Wno-unused-command-line-argument -Wno-unused-result -Wno-exceptions"
43+
)
44+
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
45+
endif(APPLE)
46+
47+
# ZLIB
48+
find_package(ZLIB)
49+
if(ZLIB_FOUND)
50+
set(HAVE_ZLIB_H "1" CACHE INTERNAL "Use zlib")
51+
set(COIN_HAS_ZLIB "1" CACHE INTERNAL "Use zlib")
52+
endif()
53+
54+
# PThread
55+
set(THREADS_PREFER_PTHREAD_FLAG ON)
56+
find_package(Threads)
57+
if(CMAKE_USE_PTHREADS_INIT)
58+
set(PTHREADS_FOUND TRUE)
59+
else()
60+
set(PTHREADS_FOUND FALSE)
61+
endif()
62+
63+
include(CheckEnv)
64+
include(CTest)
65+
66+
add_subdirectory(src)
67+
68+
include(GNUInstallDirs)
69+
install(EXPORT ${PROJECT_NAME}Targets
70+
NAMESPACE Coin::
71+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
72+
include(CMakePackageConfigHelpers)
73+
configure_package_config_file(cmake/Config.cmake.in
74+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
75+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
76+
write_basic_package_version_file(
77+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
78+
COMPATIBILITY SameMajorVersion)
79+
install(
80+
FILES
81+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
82+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
83+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
84+
COMPONENT Devel)

cmake/CheckEnv.cmake

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Flags
2+
include (CheckIncludeFile)
3+
check_include_file(math.h HAVE_MATH_H)
4+
check_include_file(ctype.h HAVE_CTYPE_H)
5+
check_include_file(inttypes.h HAVE_INTTYPES_H)
6+
check_include_file(float.h HAVE_FLOAT_H)
7+
check_include_file(ieeefp.h HAVE_IEEEFP_H)
8+
check_include_file(stdarg.h HAVE_STDARG_H)
9+
check_include_file(stddef.h HAVE_STDDEF_H)
10+
check_include_file(stdint.h HAVE_STDINT_H)
11+
check_include_file(stdio.h HAVE_STDIO_H)
12+
check_include_file(stdlib.h HAVE_STDLIB_H)
13+
check_include_file(assert.h HAVE_ASSERT_H)
14+
check_include_file(dlfcn.h HAVE_DLFCN_H)
15+
check_include_file(endian.h HAVE_ENDIAN_H)
16+
check_include_file(memory.h HAVE_MEMORY_H)
17+
check_include_file(strings.h HAVE_STRINGS_H)
18+
check_include_file(string.h HAVE_STRING_H)
19+
check_include_file(time.h HAVE_TIME_H)
20+
check_include_file(unistd.h HAVE_UNISTD_H)
21+
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
22+
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
23+
24+
include (CheckIncludeFileCXX)
25+
check_include_file_cxx(cmath HAVE_CMATH)
26+
check_include_file_cxx(cctype HAVE_CCTYPE)
27+
check_include_file_cxx(cinttypes HAVE_CINTTYPES)
28+
check_include_file_cxx(cfloat HAVE_CFLOAT)
29+
check_include_file_cxx(cieeefp HAVE_CIEEEFP)
30+
check_include_file_cxx(cstdarg HAVE_CSTDARG)
31+
check_include_file_cxx(cstddef HAVE_CSTDDEF)
32+
check_include_file_cxx(cstdint HAVE_CSTDINT)
33+
check_include_file_cxx(cstdio HAVE_CSTDIO)
34+
check_include_file_cxx(cstdlib HAVE_CSTDLIB)
35+
check_include_file_cxx(cassert HAVE_CASSERT)
36+
check_include_file_cxx(cstring HAVE_CSTRING)
37+
check_include_file_cxx(ctime HAVE_CTIME)
38+
39+
set(STDC_HEADERS 1 CACHE INTERNAL "System has ANSI C header files")
40+
41+
set(TEST_INCLUDES "")
42+
if(HAVE_CMATH)
43+
list(APPEND TEST_INCLUDES "cmath")
44+
endif()
45+
if(HAVE_CFLOAT)
46+
list(APPEND TEST_INCLUDES "cfloat")
47+
endif()
48+
if(HAVE_CIEEEFP)
49+
list(APPEND TEST_INCLUDES "cieeefp")
50+
endif()
51+
if(HAVE_MATH_H)
52+
list(APPEND TEST_INCLUDES "math.h")
53+
endif()
54+
if(HAVE_FLOAT_H)
55+
list(APPEND TEST_INCLUDES "float.h")
56+
endif()
57+
if(HAVE_IEEEFP_H)
58+
list(APPEND TEST_INCLUDES "ieeefp.h")
59+
endif()
60+
61+
# ISFINITE
62+
include(CheckCXXSourceCompiles)
63+
check_cxx_source_compiles(
64+
"#include <cmath>\nint main(){return std::isfinite(0);}"
65+
HAVE_STD_ISFINITE)
66+
include(CheckFunctionExists)
67+
include(CheckCXXSymbolExists)
68+
check_cxx_symbol_exists(isfinite "${TEST_INCLUDES}" HAVE_ISFINITE)
69+
check_cxx_symbol_exists(finite "${TEST_INCLUDES}" HAVE_FINITE)
70+
check_cxx_symbol_exists(_finite "${TEST_INCLUDES}" HAVE__FINITE)
71+
check_cxx_symbol_exists(__finite "${TEST_INCLUDES}" HAVE___FINITE)
72+
if(HAVE_STD_ISFINITE)
73+
set(COIN_C_FINITE "std::isfinite")
74+
elseif(HAVE_ISFINITE)
75+
set(COIN_C_FINITE "isfinite")
76+
elseif(HAVE_FINITE)
77+
set(COIN_C_FINITE "finite")
78+
elseif(HAVE__FINITE)
79+
set(COIN_C_FINITE "_finite")
80+
elseif(HAVE___FINITE)
81+
set(COIN_C_FINITE "__finite")
82+
else()
83+
message(FATAL_ERROR "Can't find isfinite()")
84+
endif()
85+
message(STATUS "Found isfinite: ${COIN_C_FINITE}")
86+
87+
# ISNAN
88+
include(CheckCXXSourceCompiles)
89+
check_cxx_source_compiles(
90+
"#include <cmath>\nint main(){return std::isnan(0);}"
91+
HAVE_STD_ISNAN)
92+
include(CheckFunctionExists)
93+
include(CheckCXXSymbolExists)
94+
check_cxx_symbol_exists(isnan "${TEST_INCLUDES}" HAVE_ISNAN)
95+
check_cxx_symbol_exists(_isnan "${TEST_INCLUDES}" HAVE__ISNAN)
96+
check_cxx_symbol_exists(__isnan "${TEST_INCLUDES}" HAVE___ISNAN)
97+
if(HAVE_STD_ISNAN)
98+
set(COIN_C_ISNAN "std::isnan")
99+
elseif(HAVE_ISNAN)
100+
set(COIN_C_ISNAN "isnan")
101+
elseif(HAVE__ISNAN)
102+
set(COIN_C_ISNAN "_isnan")
103+
elseif(HAVE___ISNAN)
104+
set(COIN_C_ISNAN "__isnan")
105+
else()
106+
message(FATAL_ERROR "Can't find isnan()")
107+
endif()
108+
message(STATUS "Found isnan: ${COIN_C_ISNAN}")
109+
110+
# Basic type
111+
include(CheckTypeSize)
112+
check_type_size("int64_t" SIZEOF_INT64_T)
113+
check_type_size("long long" SIZEOF_LONG_LONG)
114+
check_type_size("long" SIZEOF_LONG)
115+
check_type_size("uint64_t" SIZEOF_UINT64_T)
116+
check_type_size("unsigned long long" SIZEOF_ULONG_LONG)
117+
check_type_size("unsigned long" SIZEOF_ULONG)
118+
check_type_size("intptr_t" SIZEOF_INTPTR_T)
119+
check_type_size("int *" SIZEOF_INT_P)
120+
121+
if(SIZEOF_INT64_T EQUAL "8")
122+
set(COIN_INT64_T "int64_t")
123+
elseif(SIZEOF_LONG EQUAL "8")
124+
set(COIN_INT64_T "long")
125+
elseif(SIZEOF_LONG_LONG EQUAL "8")
126+
set(COIN_INT64_T "long long")
127+
else()
128+
message(FATAL_ERROR "Can't find suitable int64_t")
129+
endif()
130+
message(STATUS "Found int64_t: ${COIN_INT64_T}")
131+
132+
if(SIZEOF_UINT64_T EQUAL "8")
133+
set(COIN_UINT64_T "uint64_t")
134+
elseif(SIZEOF_ULONG EQUAL "8")
135+
set(COIN_INT64_T "unsigned long")
136+
elseif(SIZEOF_ULONG_LONG EQUAL "8")
137+
set(COIN_INT64_T "unsigned long long")
138+
else()
139+
message(FATAL_ERROR "Can't find suitable uint64_t")
140+
endif()
141+
message(STATUS "Found uint64_t: ${COIN_UINT64_T}")
142+
143+
if(SIZEOF_INTPTR_T)
144+
set(COIN_INTPTR_T "intptr_t")
145+
elseif(SIZEOF_INT_P)
146+
set(COIN_INTPTR_T "int *")
147+
else()
148+
message(FATAL_ERROR "Can't find suitable intptr_t")
149+
endif()
150+
message(STATUS "Found intptr_t: ${COIN_INTPTR_T}")
151+

cmake/Config.cmake.in

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@PACKAGE_INIT@
2+
3+
include(CMakeFindDependencyMacro)
4+
5+
if(@ZLIB_FOUND@)
6+
find_dependency(ZLIB)
7+
endif()
8+
9+
if(@PTHREADS_FOUND@)
10+
find_dependency(Threads)
11+
endif()
12+
13+
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

cmake/ParseAc.cmake

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function(parse_ac VERSION_STRING VERSION_MAJOR VERSION_MINOR VERSION_PATCH)
2+
file(READ "configure.ac" IN)
3+
if(IN MATCHES "AC_INIT\\(.*trunk.*\\)")
4+
message(WARNING "using trunk...")
5+
set(MAJOR 999)
6+
set(MINOR 0)
7+
set(PATCH 0)
8+
else()
9+
# AC_INIT([CoinUtils],[major.minor.patch or trunk],[url or email])
10+
string(REGEX MATCH
11+
"AC_INIT\\([^,]+,\\[([0-9]+)\\.([0-9]+)(\\.([0-9]+))?\\],[^\\)]+\\)" AC_INIT ${IN})
12+
message(STATUS "AC_INIT: ${AC_INIT}")
13+
set(MAJOR ${CMAKE_MATCH_1})
14+
set(MINOR ${CMAKE_MATCH_2})
15+
if(CMAKE_MATCH_3)
16+
set(PATCH ${CMAKE_MATCH_4})
17+
else()
18+
set(PATCH 0)
19+
endif()
20+
endif()
21+
set(VERSION "${MAJOR}.${MINOR}.${PATCH}")
22+
23+
set(${VERSION_MAJOR} ${MAJOR} PARENT_SCOPE)
24+
set(${VERSION_MINOR} ${MINOR} PARENT_SCOPE)
25+
set(${VERSION_PATCH} ${PATCH} PARENT_SCOPE)
26+
set(${VERSION_STRING} ${VERSION} PARENT_SCOPE)
27+
message(STATUS "version: ${VERSION}")
28+
endfunction()

0 commit comments

Comments
 (0)