@@ -21,7 +21,11 @@ set(PACKAGE_RELEASE_VERSION 1)
21
21
# Include cmake modules
22
22
#-----------------------------------------------------------------------------
23
23
include (GNUInstallDirs )
24
+ include (CheckIPOSupported )
24
25
include (CMakePackageConfigHelpers )
26
+ # default is "No tests"
27
+ option (BUILD_TESTING "" OFF )
28
+ include (CTest )
25
29
include (sources .cmake )
26
30
27
31
# The only direct cmake argument for now
@@ -31,42 +35,41 @@ option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"
31
35
# Compose CFLAGS
32
36
#-----------------------------------------------------------------------------
33
37
34
- # Some information copied from makefile_include.mk
38
+ # Some information ported from makefile_include.mk
35
39
36
- # Basic set
37
- set (LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow )
38
- set (LTM_C_FLAGS ${LTM_C_FLAGS} -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align )
39
- set (LTM_C_FLAGS ${LTM_C_FLAGS} -Wstrict-prototypes -Wpointer-arith -Wsystem-headers )
40
40
41
41
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
42
42
message (STATUS "Setting build type to 'Release' as none was specified." )
43
43
set (CMAKE_BUILD_TYPE "Release" )
44
44
endif ()
45
45
46
- set (CMAKE_C_FLAGS_DEBUG "-g3" )
47
- set (CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer" )
48
- set (CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2" )
49
- set (CMAKE_C_FLAGS_MINSIZEREL "-Os" )
50
-
51
- if (COMPILE_LTO )
52
- set (LTM_C_FLAGS ${LTM_C_FLAGS} -flto )
53
- set (LTM_LD_FLAGS ${LTM_LD_FLAGS} -flto )
46
+ # We only differentiate between MSVC and GCC-compatible compilers
47
+ if (MSVC )
48
+ set (LTM_C_FLAGS -W3 )
49
+ else ()
50
+ set (LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow
51
+ -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
52
+ -Wstrict-prototypes -Wpointer-arith -Wsystem-headers )
53
+ set (CMAKE_C_FLAGS_DEBUG "-g3" )
54
+ set (CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer" )
55
+ set (CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2" )
56
+ set (CMAKE_C_FLAGS_MINSIZEREL "-Os" )
54
57
endif ()
55
58
56
59
# What compiler do we have and what are their...uhm... peculiarities
57
60
if (CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang" )
58
- set ( LTM_C_FLAGS ${ LTM_C_FLAGS} -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header )
61
+ list ( APPEND LTM_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header )
59
62
# Clang requires at least '-O1' for dead code eliminiation
60
- set (CMAKE_C_FLAGS_DEBUG " ${CMAKE_C_FLAGS_DEBUG} -O1 " )
63
+ set (CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG} " )
61
64
endif ()
62
65
if (CMAKE_C_COMPILER MATCHES "mingw" )
63
- set ( LTM_C_FLAGS ${LTM_C_FLAGS} -Wno-shadow )
66
+ list ( APPEND LTM_C_FLAGS -Wno-shadow -Wno-expansion-to-defined -Wno-declaration-after-statement -Wno-bad-function-cast )
64
67
endif ()
65
68
if (CMAKE_SYSTEM_NAME MATCHES "Darwin" )
66
- set ( LTM_C_FLAGS ${ LTM_C_FLAGS} -Wno-nullability-completeness )
69
+ list ( APPEND LTM_C_FLAGS -Wno-nullability-completeness )
67
70
endif ()
68
71
if (CMAKE_SYSTEM_NAME MATCHES "CYGWIN" )
69
- set ( LTM_C_FLAGS ${ LTM_C_FLAGS} -no-undefined )
72
+ list ( APPEND LTM_C_FLAGS -no-undefined )
70
73
endif ()
71
74
72
75
# TODO: coverage (lgcov)
@@ -75,8 +78,8 @@ endif()
75
78
# in order to allow overriding our defaults.
76
79
# ${LTM_CFLAGS} means the user passed it via sth like:
77
80
# $ cmake -DLTM_CFLAGS="foo"
78
- set ( LTM_C_FLAGS ${ LTM_C_FLAGS} ${LTM_CFLAGS} )
79
- set ( LTM_LD_FLAGS ${ LTM_LD_FLAGS} ${LTM_LDFLAGS} )
81
+ list ( APPEND LTM_C_FLAGS ${LTM_CFLAGS} )
82
+ list ( APPEND LTM_LD_FLAGS ${LTM_LDFLAGS} )
80
83
81
84
#-----------------------------------------------------------------------------
82
85
# library target
@@ -100,13 +103,25 @@ target_link_options(${PROJECT_NAME} BEFORE PRIVATE
100
103
set_target_properties (${PROJECT_NAME} PROPERTIES
101
104
VERSION ${PROJECT_VERSION}
102
105
SOVERSION ${PROJECT_VERSION_MAJOR}
106
+ PUBLIC_HEADER tommath.h
103
107
)
104
108
109
+ option (COMPILE_LTO "Build with LTO enabled" )
110
+ check_ipo_supported (RESULT result )
111
+ if (result AND COMPILE_LTO )
112
+ set_property (TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE )
113
+ elseif (COMPILE_LTO )
114
+ message (WARNING "LTO is not supported for this compiler." )
115
+ endif ()
105
116
106
117
#-----------------------------------------------------------------------------
107
118
# demo target
108
119
#-----------------------------------------------------------------------------
109
- add_subdirectory (demo )
120
+
121
+ if (BUILD_TESTING )
122
+ enable_testing ()
123
+ add_subdirectory (demo )
124
+ endif ()
110
125
111
126
#-----------------------------------------------------------------------------
112
127
# Install/export targets and files
@@ -120,10 +135,7 @@ install(TARGETS ${PROJECT_NAME}
120
135
EXPORT ${TARGETS_EXPORT_NAME}
121
136
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
122
137
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
123
- )
124
-
125
- install (FILES ${HEADERS}
126
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /${PROJECT_NAME}
138
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /${PROJECT_NAME}
127
139
)
128
140
129
141
# Install libtommath.pc for pkg-config if we build a shared library
0 commit comments