~s-cecilio/lomse/master

« back to all changes in this revision

Viewing changes to CMakeLists.txt

  • Committer: cecilios
  • Date: 2010-10-10 13:35:19 UTC
  • Revision ID: git-v1:2b333198c3033525d15763b84eaf79dac9fdab80
Preparing to use CMake. Updating with new code and missing files. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#--------------------------------------------------------------------------------------
 
2
#  This file is part of the Lomse library.
 
3
#  Copyright (c) 2010 Lomse project
 
4
#
 
5
#  Lomse is free software; you can redistribute it and/or modify it under the
 
6
#  terms of the GNU General Public License as published by the Free Software Foundation,
 
7
#  either version 3 of the License, or (at your option) any later version.
 
8
#
 
9
#  Lomse is distributed in the hope that it will be useful, but WITHOUT ANY
 
10
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 
11
#  PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
12
#
 
13
#  You should have received a copy of the GNU General Public License along
 
14
#  with Lomse; if not, see <http://www.gnu.org/licenses/>.
 
15
#  
 
16
#  For any comment, suggestion or feature request, please contact the manager of
 
17
#  the project at cecilios@users.sourceforge.net
 
18
#
 
19
#-------------------------------------------------------------------------------------
 
20
#  This is a CMake configuration file for building makefiles and installfiles for
 
21
#  the library and all test/demo programs
 
22
#
 
23
#  To use it you need CMake which can be downloaded from http://www.cmake.org/
 
24
#-------------------------------------------------------------------------------------
 
25
 
 
26
project(lomse)
 
27
cmake_minimum_required(VERSION 2.6)
 
28
 
 
29
 
 
30
# Currently this file suppoorts the following generators:
 
31
#   Visual Studio 7 .NET
 
32
#   Visual Studio 2008
 
33
#   Unix makefiles
 
34
#   CodeBlocks with GCC
 
35
 
 
36
 
 
37
#----------------------------------------------------------------------
 
38
# Define possible builds
 
39
#----------------------------------------------------------------------
 
40
 
 
41
if(WIN32)
 
42
 
 
43
    if(CMAKE_GENERATOR MATCHES "CodeBlocks" OR 
 
44
       CMAKE_GENERATOR MATCHES "Visual Studio")
 
45
        
 
46
        set(CMAKE_CONFIGURATION_TYPES Debug Release)
 
47
        set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
 
48
            "Reset the configurations to what we need" FORCE)
 
49
    else()
 
50
        set( CMAKE_CONFIGURATION_TYPES RelWithDebInfo )
 
51
    endif()
 
52
 
 
53
endif()
 
54
 
 
55
if(UNIX)
 
56
 
 
57
    set(CMAKE_CONFIGURATION_TYPES RelWithDebInfo)
 
58
    list(APPEND CMAKE_CONFIGURATION_TYPES Debug Release)
 
59
 
 
60
endif()
 
61
 
 
62
 
 
63
#----------------------------------------------------------------------
 
64
# names for libraries and execs.
 
65
#----------------------------------------------------------------------
 
66
 
 
67
if( WIN32 )
 
68
    set( CMAKE_STATIC_LIBRARY_PREFIX "" )
 
69
    set( CMAKE_STATIC_LIBRARY_SUFFIX ".lib" )
 
70
    set( CMAKE_SHARED_LIBRARY_PREFIX "" )
 
71
    set( CMAKE_SHARED_LIBRARY_SUFFIX ".dll" )
 
72
    set( CMAKE_EXECUTABLE_SUFFIX ".exe" )
 
73
 
 
74
endif( WIN32 )
 
75
 
 
76
 
 
77
if( UNIX )
 
78
    set( CMAKE_STATIC_LIBRARY_PREFIX "lib" )
 
79
    set( CMAKE_STATIC_LIBRARY_SUFFIX ".a" )
 
80
    set( CMAKE_SHARED_LIBRARY_PREFIX "lib" )
 
81
    set( CMAKE_SHARED_LIBRARY_SUFFIX ".so" )
 
82
    set( CMAKE_EXECUTABLE_SUFFIX "" )
 
83
 
 
84
endif( UNIX )
 
85
 
 
86
 
 
87
# compiler settings
 
88
#------------------------------------------
 
89
 
 
90
# "Print all warnings" flag for GCC
 
91
if(UNIX)
 
92
    add_definitions(-Wall -DGCC)
 
93
endif(UNIX)
 
94
 
 
95
# "Link time code generation" flags for MSVC
 
96
if(MSVC)
 
97
    add_definitions(
 
98
        /DUNICODE /D_UNICODE
 
99
        -DWINVER=0x0400 -DWIN32 
 
100
        -D_LOMSE_WIN32_VSTUDIO
 
101
    )
 
102
    if(${CMAKE_GENERATOR} STREQUAL "Visual Studio 6")
 
103
        add_definitions(-DVC6)
 
104
    elseif(${CMAKE_GENERATOR} STREQUAL "Visual Studio 8 2005")
 
105
        add_definitions(-DVC2005)
 
106
    endif(${CMAKE_GENERATOR} STREQUAL "Visual Studio 6")
 
107
endif(MSVC)
 
108
 
 
109
# lomse: debug built
 
110
add_definitions(-D_LOMSE_DEBUG)
 
111
 
 
112
#some flags for MSVC
 
113
if(MSVC)
 
114
    set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL" ) 
 
115
    set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" )
 
116
endif()
 
117
 
 
118
 
 
119
 
 
120
# directories
 
121
#------------------------------------------
 
122
 
 
123
set(ROOT_DIR  ${CMAKE_CURRENT_SOURCE_DIR} )
 
124
set(SRC_DIR  ${ROOT_DIR}/src )
 
125
set(MAKEFILES_DIR ${ROOT_DIR}/makefiles )
 
126
 
 
127
include_directories(
 
128
    ${ROOT_DIR}/include
 
129
)
 
130
 
 
131
# The build location for libraries and for executables
 
132
set(EXECUTABLE_OUTPUT_PATH "${ROOT_DIR}/bin")
 
133
set(LIBRARY_OUTPUT_PATH "${ROOT_DIR}/bin")
 
134
 
 
135
 
 
136
 
 
137
#////////////////////////////////////////////////////////////////////////
 
138
# Target: Lomse library
 
139
#////////////////////////////////////////////////////////////////////////
 
140
 
 
141
 
 
142
# source files to compile -----------------------------------
 
143
 
 
144
set(PARSER_FILES
 
145
    ${SRC_DIR}/parser/lomse_analyser.cpp
 
146
    ${SRC_DIR}/parser/lomse_compiler.cpp
 
147
    ${SRC_DIR}/parser/lomse_ldp_elements.cpp
 
148
    ${SRC_DIR}/parser/lomse_ldp_factory.cpp
 
149
    ${SRC_DIR}/parser/lomse_linker.cpp
 
150
    ${SRC_DIR}/parser/lomse_model_builder.cpp
 
151
    ${SRC_DIR}/parser/lomse_parser.cpp
 
152
    ${SRC_DIR}/parser/lomse_reader.cpp
 
153
    ${SRC_DIR}/parser/lomse_staffobjs_table.cpp
 
154
    ${SRC_DIR}/parser/lomse_tokenizer.cpp
 
155
)
 
156
 
 
157
set(DOCUMENT_FILES
 
158
    ${SRC_DIR}/document/lomse_document.cpp
 
159
    ${SRC_DIR}/document/lomse_id_assigner.cpp
 
160
)
 
161
 
 
162
set(EXPORTERS_FILES
 
163
    ${SRC_DIR}/exporters/lomse_ldp_exporter.cpp
 
164
)
 
165
 
 
166
set(SCORE_FILES
 
167
    ${SRC_DIR}/score/lomse_score_iterator.cpp
 
168
)
 
169
 
 
170
set(MODULE_FILES
 
171
    ${SRC_DIR}/module/lomse_injectors.cpp
 
172
    ${SRC_DIR}/module/lomse_time.cpp
 
173
)
 
174
 
 
175
set(INTERNAL_MODEL_FILES
 
176
    ${SRC_DIR}/internal_model/lomse_basic_model.cpp
 
177
    ${SRC_DIR}/internal_model/lomse_basic_objects.cpp
 
178
    ${SRC_DIR}/internal_model/lomse_im_figured_bass.cpp
 
179
    ${SRC_DIR}/internal_model/lomse_im_note.cpp
 
180
    ${SRC_DIR}/internal_model/lomse_internal_model.cpp
 
181
)
 
182
 
 
183
set(MVC_FILES
 
184
    ${SRC_DIR}/mvc/lomse_view.cpp
 
185
)
 
186
 
 
187
set(GRAPHIC_MODEL_FILES
 
188
    ${SRC_DIR}/graphic_model/lomse_document_layouter.cpp
 
189
    ${SRC_DIR}/graphic_model/lomse_gm_basic.cpp
 
190
    ${SRC_DIR}/graphic_model/lomse_score_layouter.cpp
 
191
)
 
192
 
 
193
set(ALL_SOURCES 
 
194
    ${PARSER_FILES} ${DOCUMENT_FILES} ${EXPORTERS_FILES} ${SCORE_FILES}
 
195
    ${MODULE_FILES} ${INTERNAL_MODEL_FILES} ${MVC_FILES}
 
196
    ${GRAPHIC_MODEL_FILES}
 
197
)
 
198
 
 
199
 
 
200
# Adds folders for Visual Studio and other IDEs -----------------------------------
 
201
source_group( "document"        FILES ${DOCUMENT_FILES} )
 
202
source_group( "exporters"       FILES ${EXPORTERS_FILES} )
 
203
source_group( "graphic_model"   FILES ${GRAPHIC_MODEL_FILES} )
 
204
source_group( "internal_model"  FILES ${INTERNAL_MODEL_FILES} )
 
205
source_group( "module"          FILES ${MODULE_FILES} )
 
206
source_group( "mvc"             FILES ${MVC_FILES} )
 
207
source_group( "parser"          FILES ${PARSER_FILES} )
 
208
source_group( "score"           FILES ${SCORE_FILES} )
 
209
 
 
210
 
 
211
 
 
212
# library makefile generation. Static library
 
213
#-------------------------------------------------------------
 
214
 
 
215
set(LOMSE  lomse)
 
216
add_library( ${LOMSE} STATIC ${ALL_SOURCES} )
 
217
 
 
218
 
 
219
# hack to remove 'Debug' subdirectory from output path. -------------
 
220
# see: http://www.cmake.org/Bug/view.php?id=8243
 
221
if(MSVC)
 
222
    set_target_properties(${LOMSE}  PROPERTIES  PREFIX "../")
 
223
endif()
 
224
 
 
225
# once built, place library at lomse/bin
 
226
set_target_properties(${LOMSE}  PROPERTIES
 
227
    RUNTIME_OUTPUT_DIRECTORY  ${ROOT_DIR}/bin )
 
228
    
 
229
    
 
230
 
 
231
# library makefile generation. Dynamic library
 
232
#-------------------------------------------------------------
 
233
 
 
234
set(LOMSE_SH  lomse_dll)
 
235
add_library( ${LOMSE_SH} SHARED ${ALL_SOURCES} )
 
236
 
 
237
# The library target LOMSE_SH has a default OUTPUT_NAME of "lomse_dll", so change it.
 
238
set_target_properties(${LOMSE_SH} PROPERTIES OUTPUT_NAME "liblomse")
 
239
 
 
240
 
 
241
# hack to remove 'Debug' subdirectory from output path. --------------
 
242
# see: http://www.cmake.org/Bug/view.php?id=8243
 
243
if(MSVC)
 
244
    set_target_properties(${LOMSE}  PROPERTIES  PREFIX "../")
 
245
endif()
 
246
 
 
247
 
 
248
#////////////////////////////////////////////////////////////////////////
 
249
# Target: program for testing the library
 
250
#////////////////////////////////////////////////////////////////////////
 
251
 
 
252
set (TESTLIB  testlib)
 
253
 
 
254
include_directories(
 
255
    ${ROOT_DIR}/include
 
256
    ${ROOT_DIR}/packages/UnitTest++/src
 
257
)
 
258
 
 
259
link_directories(
 
260
    ${ROOT_DIR}/packages/UnitTest++/lib 
 
261
    ${LIBRARY_OUTPUT_PATH} 
 
262
)
 
263
 
 
264
set( CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "/NODEFAULTLIB:LIBCD" )
 
265
 
 
266
 
 
267
# source files to compile -----------------------------------
 
268
add_executable( ${TESTLIB} 
 
269
        ${SRC_DIR}/tests/lomse_test_analyser.cpp
 
270
        ${SRC_DIR}/tests/lomse_test_colstaffobjs_builder.cpp
 
271
        ${SRC_DIR}/tests/lomse_test_compiler.cpp
 
272
        ${SRC_DIR}/tests/lomse_test_document.cpp
 
273
        ${SRC_DIR}/tests/lomse_test_document_layouter.cpp
 
274
        ${SRC_DIR}/tests/lomse_test_elements.cpp
 
275
        ${SRC_DIR}/tests/lomse_test_gm_objects.cpp
 
276
        ${SRC_DIR}/tests/lomse_test_graphic_model.cpp
 
277
        ${SRC_DIR}/tests/lomse_test_internal_model.cpp
 
278
        ${SRC_DIR}/tests/lomse_test_model_builder.cpp
 
279
        ${SRC_DIR}/tests/lomse_test_parser.cpp
 
280
        ${SRC_DIR}/tests/lomse_test_reader.cpp
 
281
        ${SRC_DIR}/tests/lomse_test_score_layouter.cpp
 
282
        ${SRC_DIR}/tests/lomse_test_stack.cpp
 
283
        ${SRC_DIR}/tests/lomse_test_tokenizer.cpp
 
284
        ${SRC_DIR}/tests/lomse_test_tree.cpp
 
285
        ${SRC_DIR}/tests/lomse_test_view.cpp
 
286
        ${SRC_DIR}/tests/lomse_the_test_runner.cpp
 
287
)
 
288
 
 
289
 
 
290
# libraries to link -----------------------------------
 
291
if(UNIX)
 
292
    target_link_libraries ( ${TESTLIB} liblomse.so UnitTest++.vsnet2003.so )
 
293
elseif(WIN32)
 
294
    target_link_libraries ( ${TESTLIB} lomse.lib UnitTest++.vsnet2003.lib )
 
295
endif()
 
296
 
 
297
# properties -----------------------------------
 
298
if(WIN32)
 
299
    set_target_properties(${TESTLIB} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCD" )
 
300
    set_target_properties(${TESTLIB} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
 
301
    set_target_properties(${TESTLIB} PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE")
 
302
    set_target_properties(${TESTLIB} PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE")
 
303
    set_target_properties(${TESTLIB} PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE")
 
304
endif(WIN32)
 
305
 
 
306
 
 
307
# once generated, run tests
 
308
add_custom_command(
 
309
    TARGET ${TESTLIB} POST_BUILD
 
310
    COMMAND ${EXECUTABLE_OUTPUT_PATH}/debug/testlib.exe
 
311
    WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
 
312
)
 
313
 
 
314
 
 
315
 
 
316
# installation
 
317
#-----------------------------------------------------------------
 
318
 
 
319
# install the executable
 
320
#------------------------------------------
 
321
 
 
322
#if(UNIX)
 
323
#    install (TARGETS  ${TESTLIB}  DESTINATION  ${ROOT_DIR}/makefiles/unix )
 
324
#endif()
 
325
 
 
326
#if(WIN32)
 
327
#    install (TARGETS  ${TESTLIB}  DESTINATION  ${ROOT_DIR}/makefiles/win32 )
 
328
#endif()
 
329
 
 
330
 
 
331
# library install
 
332
# You can change the install location by running cmake like this:
 
333
#
 
334
#   cmake -DCMAKE_INSTALL_PREFIX=/new/install/prefix
 
335
#
 
336
# By default, the prefix is "/usr/local"
 
337
 
338
#if( UNIX AND NOT APPLE )
 
339
#    install( TARGETS ${LOMSE} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
 
340
#endif()
 
341
 
 
342
## Set the path of the application executable
 
343
#if( MSVC )
 
344
#    set( EXE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/${TESTLIB}${CMAKE_EXECUTABLE_SUFFIX} )
 
345
#else()
 
346
#    set( EXE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTLIB}${CMAKE_EXECUTABLE_SUFFIX} )
 
347
#endif()
 
348