e8f378c09251982d043a3a816368fbcdc90eedf1
[blender.git] / CMake / macros.cmake
1 MACRO(BLENDERLIB_NOLIST
2   name
3   sources
4   includes)
5
6   # Gather all headers
7   FILE(GLOB_RECURSE INC_ALL *.h)
8      
9   INCLUDE_DIRECTORIES(${includes})
10   ADD_LIBRARY(${name} ${INC_ALL} ${sources})
11
12   # Group by location on disk
13   SOURCE_GROUP(Files FILES CMakeLists.txt)
14   SET(ALL_FILES ${sources} ${INC_ALL})
15   FOREACH(SRC ${ALL_FILES})
16     STRING(REGEX REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "Files" REL_DIR "${SRC}")
17     STRING(REGEX REPLACE "[\\\\/][^\\\\/]*$" "" REL_DIR "${REL_DIR}")
18     STRING(REGEX REPLACE "^[\\\\/]" "" REL_DIR "${REL_DIR}")
19     IF(REL_DIR)
20       SOURCE_GROUP(${REL_DIR} FILES ${SRC})
21     ELSE(REL_DIR)
22       SOURCE_GROUP(Files FILES ${SRC})
23     ENDIF(REL_DIR)
24   ENDFOREACH(SRC)
25
26   MESSAGE(STATUS "Configuring library ${name}")
27 ENDMACRO(BLENDERLIB_NOLIST)
28
29 MACRO(BLENDERLIB
30   name
31   sources
32   includes)
33
34   BLENDERLIB_NOLIST(${name} "${sources}" "${includes}")
35
36   # Add to blender's list of libraries
37   FILE(APPEND ${CMAKE_BINARY_DIR}/cmake_blender_libs.txt "${name};")
38 ENDMACRO(BLENDERLIB)
39
40 MACRO(SETUP_LIBDIRS)
41   # see "cmake --help-policy CMP0003"
42   if(COMMAND cmake_policy)
43     CMAKE_POLICY(SET CMP0003 NEW)
44   endif(COMMAND cmake_policy)
45   
46   LINK_DIRECTORIES(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH} ${LIBSAMPLERATE_LIBPATH})
47   
48   IF(WITH_PYTHON)
49     LINK_DIRECTORIES(${PYTHON_LIBPATH})
50   ENDIF(WITH_PYTHON)
51   IF(WITH_INTERNATIONAL)
52     LINK_DIRECTORIES(${ICONV_LIBPATH})
53     LINK_DIRECTORIES(${GETTEXT_LIBPATH})
54   ENDIF(WITH_INTERNATIONAL)
55   IF(WITH_SDL)
56     LINK_DIRECTORIES(${SDL_LIBPATH})
57   ENDIF(WITH_SDL)
58   IF(WITH_FFMPEG)
59     LINK_DIRECTORIES(${FFMPEG_LIBPATH})
60   ENDIF(WITH_FFMPEG)
61   IF(WITH_OPENEXR)
62     LINK_DIRECTORIES(${OPENEXR_LIBPATH})
63   ENDIF(WITH_OPENEXR)
64   IF(WITH_QUICKTIME)
65     LINK_DIRECTORIES(${QUICKTIME_LIBPATH})
66   ENDIF(WITH_QUICKTIME)
67   IF(WITH_OPENAL)
68     LINK_DIRECTORIES(${OPENAL_LIBPATH})
69   ENDIF(WITH_OPENAL)
70   IF(WITH_JACK)
71     LINK_DIRECTORIES(${JACK_LIBPATH})
72   ENDIF(WITH_JACK)
73   IF(WITH_SNDFILE)
74     LINK_DIRECTORIES(${SNDFILE_LIBPATH})
75   ENDIF(WITH_SNDFILE)
76   IF(WITH_FFTW3)
77     LINK_DIRECTORIES(${FFTW3_LIBPATH})
78   ENDIF(WITH_FFTW3)
79
80   IF(WIN32)
81     LINK_DIRECTORIES(${PTHREADS_LIBPATH})
82   ENDIF(WIN32)
83 ENDMACRO(SETUP_LIBDIRS)
84
85 MACRO(SETUP_LIBLINKS
86   target)
87   SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS} ")
88
89   TARGET_LINK_LIBRARIES(${target} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${JPEG_LIBRARY} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} ${LLIBS})
90
91   # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
92   IF(WITH_PYTHON)
93     TARGET_LINK_LIBRARIES(${target} ${PYTHON_LINKFLAGS})
94   
95     IF(WIN32)
96       TARGET_LINK_LIBRARIES(${target} debug ${PYTHON_LIB}_d)
97       TARGET_LINK_LIBRARIES(${target} optimized ${PYTHON_LIB})
98     ELSE(WIN32)
99       TARGET_LINK_LIBRARIES(${target} ${PYTHON_LIB})
100     ENDIF(WIN32)
101   ENDIF(WITH_PYTHON)
102   
103   TARGET_LINK_LIBRARIES(${target} ${OPENGL_glu_LIBRARY} ${JPEG_LIB} ${PNG_LIB} ${ZLIB_LIB})
104   TARGET_LINK_LIBRARIES(${target} ${FREETYPE_LIBRARY} ${LIBSAMPLERATE_LIB})
105
106   IF(WITH_INTERNATIONAL)
107     TARGET_LINK_LIBRARIES(${target} ${GETTEXT_LIB})
108   ENDIF(WITH_INTERNATIONAL)
109   IF(WITH_OPENAL)
110     TARGET_LINK_LIBRARIES(${target} ${OPENAL_LIBRARY})
111   ENDIF(WITH_OPENAL)
112   IF(WITH_FFTW3)  
113     TARGET_LINK_LIBRARIES(${target} ${FFTW3_LIB})
114   ENDIF(WITH_FFTW3)
115   IF(WITH_JACK)
116     TARGET_LINK_LIBRARIES(${target} ${JACK_LIB})
117   ENDIF(WITH_JACK)
118   IF(WITH_SNDFILE)
119     TARGET_LINK_LIBRARIES(${target} ${SNDFILE_LIB})
120   ENDIF(WITH_SNDFILE)
121   IF(WITH_SDL)
122     TARGET_LINK_LIBRARIES(${target} ${SDL_LIBRARY})
123   ENDIF(WITH_SDL)
124   IF(WIN32)
125     TARGET_LINK_LIBRARIES(${target} ${ICONV_LIB})
126   ENDIF(WIN32)
127   IF(WITH_QUICKTIME)
128     TARGET_LINK_LIBRARIES(${target} ${QUICKTIME_LIB})
129   ENDIF(WITH_QUICKTIME)
130   IF(WITH_OPENEXR)
131     TARGET_LINK_LIBRARIES(${target} ${OPENEXR_LIB})
132   ENDIF(WITH_OPENEXR)
133   IF(WITH_FFMPEG)
134     TARGET_LINK_LIBRARIES(${target} ${FFMPEG_LIB})
135   ENDIF(WITH_FFMPEG)
136   IF(WIN32)
137     TARGET_LINK_LIBRARIES(${target} ${PTHREADS_LIB})
138   ENDIF(WIN32)
139 ENDMACRO(SETUP_LIBLINKS)
140