1- cmake_minimum_required (VERSION 2.8.0 )
1+ cmake_minimum_required (VERSION 2.8.12 )
22
33project (libmodplug)
4+
5+ set (VERSION "0.8.9.1" )
6+
7+ option (BUILD_SHARED_LIBS "Build Shared Library (DLL)" OFF )
8+
49add_definitions (-DMODPLUG_BUILD)
510
611include (CheckFunctionExists)
712include (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 ()
838
939include_directories (AFTER
1040 src
1141 src/libmodplug
1242 ${PROJECT_BINARY_DIR}
13- )
43+ )
1444
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 ()
1750endif ()
1851
1952if (WIN32 )
2053 add_definitions (-D_USE_MATH_DEFINES)
2154 add_definitions (-DNOMINMAX)
2255endif ()
2356
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)
5760endif ()
5861
5962check_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 ()
6666
6767if (BUILD_SHARED_LIBS )
68- # User wants to build Dynamic Libraries,
69- # so change the LIB_TYPE variable to CMake keyword 'SHARED'
7068 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 )
7377 add_definitions (-DMODPLUG_STATIC)
74- endif ( BUILD_SHARED_LIBS )
78+ endif ( )
7579
7680add_library (modplug ${LIB_TYPE}
7781 src/libmodplug/it_defs.h
@@ -115,7 +119,24 @@ add_library(modplug ${LIB_TYPE}
115119 src/sndfile.cpp
116120 src/sndmix.cpp
117121 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 ()
119140
120141# install the library:
121142include (GNUInstallDirs)
@@ -128,17 +149,13 @@ install(TARGETS modplug
128149# install the headers:
129150install (FILES
130151 src/modplug.h
131- ${HEADERS_CXX}
152+ src/libmodplug/it_defs.h
153+ src/libmodplug/sndfile.h
154+ src/libmodplug/stdafx.h
132155
133156 DESTINATION
134157 ${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+ )
142159
143160if (NOT WIN32 )
144161 set (prefix ${CMAKE_INSTALL_PREFIX} )
@@ -149,6 +166,6 @@ if (NOT WIN32)
149166
150167 # install pkg-config file:
151168 install (FILES "${PROJECT_BINARY_DIR} /libmodplug.pc"
152- DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig
169+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig
153170 )
154171endif (NOT WIN32 )
0 commit comments