1
- cmake_minimum_required (VERSION 2.8.0 )
1
+ cmake_minimum_required (VERSION 2.8.12 )
2
2
3
3
project (libmodplug)
4
+
5
+ set (VERSION "0.8.9.1" )
6
+
7
+ option (BUILD_SHARED_LIBS "Build Shared Library (DLL)" OFF )
8
+
4
9
add_definitions (-DMODPLUG_BUILD)
5
10
6
11
include (CheckFunctionExists)
7
12
include (CheckIncludeFile)
13
+ include (CheckCCompilerFlag)
14
+ include (CheckCSourceCompiles)
15
+ include (TestBigEndian)
16
+
17
+ TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
18
+ if (WORDS_BIGENDIAN)
19
+ add_definitions (-DWORDS_BIGENDIAN=1)
20
+ endif ()
21
+
22
+ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" )
23
+ add_definitions (-Wall)
24
+ # check symbol visibility attributes
25
+ set (OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} " )
26
+ if (NOT WIN32 AND NOT CYGWIN )
27
+ set (CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror" )
28
+ check_c_source_compiles("int foo(void) __attribute__((visibility(\" default\" )));
29
+ int main(void) {return 0;}" HAVE_VISIBILITY_DEFAULT)
30
+ if (HAVE_VISIBILITY_DEFAULT)
31
+ check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN)
32
+ endif ()
33
+ endif ()
34
+ set (CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined" )
35
+ check_c_compiler_flag("" HAVE_NO_UNDEFINED)
36
+ set (CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} " )
37
+ endif ()
8
38
9
39
include_directories (AFTER
10
40
src
11
41
src/libmodplug
12
42
${PROJECT_BINARY_DIR}
13
- )
43
+ )
14
44
15
- if (UNIX )
16
- set (CMAKE_REQUIRED_LIBRARIES m)
45
+ if (UNIX AND NOT APPLE )
46
+ find_library (MATH_LIB m)
47
+ if (MATH_LIB)
48
+ set (CMAKE_REQUIRED_LIBRARIES m)
49
+ endif ()
17
50
endif ()
18
51
19
52
if (WIN32 )
20
53
add_definitions (-D_USE_MATH_DEFINES)
21
54
add_definitions (-DNOMINMAX)
22
55
endif ()
23
56
24
- if (WIN32 AND NOT (MINGW OR MSYS))
25
- set (MSINTTYPES_PATH "$ENV{MSINTTYPES_PATH} " CACHE PATH "search path for inttypes.h and stdint.h" )
26
-
27
- find_path (STDINT_INCLUDE_DIR
28
- stdint.h
29
- PATHS
30
- ${MSINTTYPES_PATH} )
31
-
32
- if (STDINT_INCLUDE_DIR)
33
- add_definitions (-DHAVE_STDINT_H)
34
- include_directories (AFTER "${STDINT_INCLUDE_DIR} " )
35
- endif ()
36
-
37
- find_path (INTTYPES_INCLUDE_DIR
38
- inttypes.h
39
- PATHS
40
- ${MSINTTYPES_PATH} )
41
-
42
- if (INTTYPES_INCLUDE_DIR)
43
- add_definitions (-DHAVE_INTTYPES_H)
44
- include_directories (AFTER "${INTTYPES_INCLUDE_DIR} " )
45
- endif ()
46
-
47
- if (NOT STDINT_INCLUDE_DIR OR NOT INTTYPES_INCLUDE_DIR)
48
- message (WARNING
49
- "Compilation may fail if inttypes.h is not natively supported by the compiler."
50
- "You can get inttypes.h from http://code.google.com/p/msinttypes/" )
51
- endif ()
52
- else ()
53
- check_include_file("stdint.h" HAVE_STDINT)
54
- if (HAVE_STDINT)
55
- add_definitions (-DHAVE_STDINT_H)
56
- endif ()
57
+ check_include_file("stdint.h" HAVE_STDINT)
58
+ if (HAVE_STDINT)
59
+ add_definitions (-DHAVE_STDINT_H)
57
60
endif ()
58
61
59
62
check_function_exists("sinf" HAVE_SINF)
60
-
61
- # Allow the developer to select if Dynamic or Static libraries are built
62
- option (BUILD_SHARED_LIBS "Build Shared Library (DLL)" OFF )
63
-
64
- # Set the LIB_TYPE variable to STATIC
65
- set (LIB_TYPE STATIC )
63
+ if (HAVE_SINF)
64
+ add_definitions (-DHAVE_SINF)
65
+ endif ()
66
66
67
67
if (BUILD_SHARED_LIBS )
68
- # User wants to build Dynamic Libraries,
69
- # so change the LIB_TYPE variable to CMake keyword 'SHARED'
70
68
set (LIB_TYPE SHARED)
71
- add_definitions (-DDLL_EXPORT)
72
- else (BUILD_SHARED_LIBS )
69
+ if (WIN32 OR CYGWIN )
70
+ add_definitions (-DDLL_EXPORT)
71
+ elseif (HAVE_VISIBILITY_HIDDEN)
72
+ add_definitions (-fvisibility=hidden)
73
+ add_definitions ("-DSYM_VISIBILITY" )
74
+ endif ()
75
+ else ()
76
+ set (LIB_TYPE STATIC )
73
77
add_definitions (-DMODPLUG_STATIC)
74
- endif ( BUILD_SHARED_LIBS )
78
+ endif ( )
75
79
76
80
add_library (modplug ${LIB_TYPE}
77
81
src/libmodplug/it_defs.h
@@ -115,7 +119,24 @@ add_library(modplug ${LIB_TYPE}
115
119
src/sndfile.cpp
116
120
src/sndmix.cpp
117
121
src/tables.h
118
- )
122
+ )
123
+
124
+ if (BUILD_SHARED_LIBS )
125
+ if (APPLE )
126
+ target_link_libraries (modplug -Wl,-undefined,error)
127
+ target_link_libraries (modplug -Wl,-compatibility_version,2.0.0)
128
+ target_link_libraries (modplug -Wl,-current_version,2.0.0)
129
+ else ()
130
+ if (HAVE_NO_UNDEFINED)
131
+ target_link_libraries (modplug -Wl,--no -undefined)
132
+ endif ()
133
+ set_target_properties (modplug PROPERTIES
134
+ VERSION 1.0.0 SOVERSION 1)
135
+ endif ()
136
+ if (MATH_LIB)
137
+ target_link_libraries (modplug m)
138
+ endif ()
139
+ endif ()
119
140
120
141
# install the library:
121
142
include (GNUInstallDirs)
@@ -128,17 +149,13 @@ install(TARGETS modplug
128
149
# install the headers:
129
150
install (FILES
130
151
src/modplug.h
131
- ${HEADERS_CXX}
152
+ src/libmodplug/it_defs.h
153
+ src/libmodplug/sndfile.h
154
+ src/libmodplug/stdafx.h
132
155
133
156
DESTINATION
134
157
${CMAKE_INSTALL_INCLUDEDIR} /libmodplug
135
- )
136
-
137
- set (VERSION "0.8.9.1" )
138
-
139
- if (HAVE_SINF)
140
- add_definitions (-DHAVE_SINF)
141
- endif (HAVE_SINF)
158
+ )
142
159
143
160
if (NOT WIN32 )
144
161
set (prefix ${CMAKE_INSTALL_PREFIX} )
@@ -149,6 +166,6 @@ if (NOT WIN32)
149
166
150
167
# install pkg-config file:
151
168
install (FILES "${PROJECT_BINARY_DIR} /libmodplug.pc"
152
- DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig
169
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig
153
170
)
154
171
endif (NOT WIN32 )
0 commit comments