1
project(jom)
2
cmake_minimum_required(VERSION 2.6)
3
4
5
option(JOM_ENABLE_TESTS "Enable unit-testing for jom" OFF)
6
7
if(JOM_ENABLE_TESTS)
8
    enable_testing()
9
endif(JOM_ENABLE_TESTS)
10
11
12
# where to look first for cmake modules
13
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules;${CMAKE_MODULE_PATH}")
14
15
# search for Qt4 - it is required
16
find_package(Qt4 REQUIRED)
17
18
# some general definitions & the directories that should be included
19
add_definitions(${QT_DEFINITIONS})
20
include_directories(
21
  ${QT_INCLUDES}
22
  ${CMAKE_BINARY_DIR}
23
  src/jomlib
24
)
25
if(MSVC)
26
    add_definitions(
27
      -D_CRT_SECURE_NO_DEPRECATE
28
    )
29
   # Qt disables the native wchar_t type, do it too to avoid linking issues
30
   set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Zc:wchar_t-" )
31
endif(MSVC)
32
add_definitions(
33
  -DQT_NO_CAST_TO_ASCII
34
  -DQT_USE_FAST_CONCATENATION
35
  -DQT_USE_FAST_OPERATOR_PLUS
36
  -DUNICODE
37
)
38
39
# in subdirectory src:
40
#
41
set(JOM_MOCS
42
    src/jomlib/targetexecutor.h
43
    src/jomlib/process.h
44
    src/jomlib/commandexecutor.h
45
)
46
47
set(JOM_SRCS
48
    src/jomlib/commandexecutor.cpp
49
    src/jomlib/dependencygraph.cpp
50
    src/jomlib/exception.cpp
51
    src/jomlib/fastfileinfo.cpp
52
    src/jomlib/filetime.cpp
53
    src/jomlib/helperfunctions.cpp
54
    src/jomlib/iocompletionport.cpp
55
    src/jomlib/macrotable.cpp
56
    src/jomlib/makefile.cpp
57
    src/jomlib/makefilefactory.cpp
58
    src/jomlib/makefilelinereader.cpp
59
    src/jomlib/options.cpp
60
    src/jomlib/parser.cpp
61
    src/jomlib/ppexpr_grammar.cpp
62
    src/jomlib/ppexprparser.cpp
63
    src/jomlib/preprocessor.cpp
64
    src/jomlib/process.cpp
65
    src/jomlib/targetexecutor.cpp
66
    src/jomlib/dependencygraph.h
67
    src/jomlib/exception.h
68
    src/jomlib/fastfileinfo.h
69
    src/jomlib/filetime.h
70
    src/jomlib/helperfunctions.h
71
    src/jomlib/macrotable.h
72
    src/jomlib/makefile.h
73
    src/jomlib/makefilefactory.h
74
    src/jomlib/makefilelinereader.h
75
    src/jomlib/options.h
76
    src/jomlib/parser.h
77
    src/jomlib/ppexpr_grammar_p.h
78
    src/jomlib/ppexprparser.h
79
    src/jomlib/preprocessor.h
80
    src/jomlib/stable.h
81
)
82
83
 # run moc on all headers and add the moc files to the SRCS
84
 qt4_wrap_cpp(JOM_GENERATED_SRCS ${JOM_MOCS})
85
 list(APPEND JOM_SRCS ${JOM_GENERATED_SRCS} ${JOM_MOCS})
86
87
88
 set(JOM_APP_MOCS
89
    src/app/application.h
90
)
91
 set(JOM_APP_SRCS
92
    src/app/main.cpp
93
    src/app/application.cpp
94
)
95
 qt4_wrap_cpp(JOM_APP_GENERATED_SRCS ${JOM_APP_MOCS})
96
 list(APPEND JOM_APP_SRCS ${JOM_APP_GENERATED_SRCS} ${JOM_APP_MOCS})
97
 source_group("Generated Sources" FILES ${JOM_GENERATED_SRCS} ${JOM_APP_GENERATED_SRCS})
98
99
 add_executable(jom ${JOM_APP_SRCS} ${JOM_SRCS})
100
 target_link_libraries(jom ${QT_QTMAIN_LIBRARY} ${QT_QTCORE_LIBRARY} ws2_32)
101
102
 # install binaries to bin/, libraries to lib/ and import libraries to lib/ too
103
 install(TARGETS jom  RUNTIME DESTINATION bin
104
                      LIBRARY DESTINATION lib
105
                      ARCHIVE DESTINATION lib)
106
107
 # if we want to use tests:
108
 if(JOM_ENABLE_TESTS)
109
     # in subdirectory tests:
110
     set(TESTS_SRCS tests/tests.cpp tests/tests.h)
111
     qt4_wrap_cpp(TESTS_SRCS tests/tests.h)
112
     add_executable(jom-test ${TESTS_SRCS} ${JOM_SRCS})
113
     target_link_libraries(jom-test ${QT_QTMAIN_LIBRARY}
114
                                    ${QT_QTCORE_LIBRARY}
115
                                    ${QT_QTTEST_LIBRARY})
116
117
     # copy the data directory 'makefiles' over into the build directory as the tests should be run from there
118
     file(GLOB_RECURSE JOM_TEST_DATA RELATIVE ${CMAKE_SOURCE_DIR}/tests/makefiles/ "tests/makefiles/*")
119
     file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/makefiles)
120
     foreach(_file ${JOM_TEST_DATA})
121
         configure_file(${CMAKE_SOURCE_DIR}/tests/makefiles/${_file} ${CMAKE_BINARY_DIR}/makefiles/${_file} COPY_ONLY)
122
     endforeach(_file ${JOM_TEST_DATA})
123
124
     # add one unit test per function:
125
     # you can run the unittests all at once using 'make test' from the build directory
126
     # to produce the list: jom-test --functions | sed 's|[(][)]||'
127
     set(TEST_NAMES
128
        includeFiles
129
        includeCycle
130
        macros
131
        invalidMacros
132
        preprocessorExpressions
133
        preprocessorDivideByZero
134
        preprocessorInvalidExpressions
135
        conditionals
136
        dotDirectives
137
        descriptionBlocks
138
        inferenceRules
139
        cycleInTargets
140
        dependentsWithSpace
141
        multipleTargets
142
        comments
143
        fileNameMacros
144
        fileNameMacrosInDependents
145
        windowsPathsInTargetName
146
        caseInsensitiveDependents
147
        environmentVariables
148
        ignoreExitCodes
149
        inlineFiles
150
        unicodeFiles
151
        builtin_cd
152
        suffixes
153
        nonexistentDependent
154
        outOfDateCheck
155
     )
156
     foreach(TEST_NAME ${TEST_NAMES})
157
        add_test(${TEST_NAME} jom-test ${TEST_NAME})
158
     endforeach()
159
160
 endif(JOM_ENABLE_TESTS)