summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2018-11-16 17:10:19 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2018-11-20 07:22:02 +0000
commit645785b5eddd1b90cea447d6a2eb7a53c255a820 (patch)
treecde298f81f1dc55f300ec1f05bfce192b07ab48e
parent86955eadae3047a68b79fa861fd926575680dd24 (diff)
Split CMakeLists.txt
Do not use one monolithic file for the whole of jom. Also, modernize the project files. Change-Id: Iea764aa40bfa6f0064d864521a0726ca107df486 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
-rw-r--r--CMakeLists.txt169
-rw-r--r--src/app/CMakeLists.txt12
-rw-r--r--src/jomlib/CMakeLists.txt58
-rw-r--r--tests/CMakeLists.txt11
4 files changed, 92 insertions, 158 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a981fc..d2b4014 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,166 +1,19 @@
-project(jom)
-cmake_minimum_required(VERSION 2.8.11)
+cmake_minimum_required(VERSION 3.6)
+project(jom LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
-
-option(JOM_ENABLE_TESTS "Enable unit-testing for jom" OFF)
-
-if(JOM_ENABLE_TESTS)
- enable_testing()
-endif(JOM_ENABLE_TESTS)
+enable_testing()
# where to look first for cmake modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules;${CMAKE_MODULE_PATH}")
-find_package(Qt5Core 5.2.0 REQUIRED)
-
-include_directories(
- ${CMAKE_BINARY_DIR}
- src/jomlib
- )
-if(MSVC)
- add_definitions(
- -D_CRT_SECURE_NO_WARNINGS
- )
-endif(MSVC)
-add_definitions(
- -DQT_NO_CAST_FROM_ASCII
- -DQT_NO_CAST_TO_ASCII
- -DUNICODE
- )
-
-set(JOM_MOCS
- src/jomlib/targetexecutor.h
- src/jomlib/jomprocess.h
- src/jomlib/commandexecutor.h
- src/jomlib/jobclient.h
- src/jomlib/jobclientacquirehelper.h
- )
-
-set(JOM_SRCS
- src/jomlib/commandexecutor.cpp
- src/jomlib/dependencygraph.cpp
- src/jomlib/exception.cpp
- src/jomlib/fastfileinfo.cpp
- src/jomlib/filetime.cpp
- src/jomlib/helperfunctions.cpp
- src/jomlib/jobclient.cpp
- src/jomlib/jobclientacquirehelper.cpp
- src/jomlib/jobserver.cpp
- src/jomlib/macrotable.cpp
- src/jomlib/makefile.cpp
- src/jomlib/makefilefactory.cpp
- src/jomlib/makefilelinereader.cpp
- src/jomlib/options.cpp
- src/jomlib/parser.cpp
- src/jomlib/ppexpr_grammar.cpp
- src/jomlib/ppexprparser.cpp
- src/jomlib/preprocessor.cpp
- src/jomlib/targetexecutor.cpp
- src/jomlib/dependencygraph.h
- src/jomlib/exception.h
- src/jomlib/fastfileinfo.h
- src/jomlib/filetime.h
- src/jomlib/helperfunctions.h
- src/jomlib/macrotable.h
- src/jomlib/makefile.h
- src/jomlib/makefilefactory.h
- src/jomlib/makefilelinereader.h
- src/jomlib/options.h
- src/jomlib/parser.h
- src/jomlib/ppexpr_grammar_p.h
- src/jomlib/ppexprparser.h
- src/jomlib/preprocessor.h
- src/jomlib/stable.h
- )
-
-# run moc on all headers and add the moc files to the SRCS
-list(APPEND JOM_SRCS ${JOM_GENERATED_SRCS} ${JOM_MOCS})
+find_package(Qt5 5.2.0 REQUIRED COMPONENTS Core)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
+add_subdirectory(src/jomlib)
+add_subdirectory(src/app)
-if(WIN32)
- list(APPEND JOM_SRCS
- src/jomlib/iocompletionport.h
- src/jomlib/iocompletionport.cpp
- src/jomlib/jomprocess.cpp
- )
-else()
- add_definitions(
- -DUSE_QPROCESS
- )
- list(APPEND JOM_SRCS
- src/jomlib/jomprocess_qt.cpp
- )
+if(BUILD_TESTING)
+ add_subdirectory(tests)
endif()
-
-set(JOM_APP_MOCS
- src/app/application.h
- )
-set(JOM_APP_SRCS
- src/app/main.cpp
- src/app/application.cpp
- )
-list(APPEND JOM_APP_SRCS ${JOM_APP_GENERATED_SRCS} ${JOM_APP_MOCS})
-source_group("Generated Sources" FILES ${JOM_GENERATED_SRCS} ${JOM_APP_GENERATED_SRCS})
-
-add_executable(jom ${JOM_APP_SRCS} ${JOM_SRCS})
-if(WIN32)
- target_link_libraries(jom Qt5::Core ws2_32)
-else(WIN32)
- target_link_libraries(jom Qt5::Core)
-endif(WIN32)
-
-# install binaries to bin/, libraries to lib/ and import libraries to lib/ too
-install(TARGETS jom RUNTIME DESTINATION bin
- LIBRARY DESTINATION lib
- ARCHIVE DESTINATION lib)
-
-# if we want to use tests:
-if(JOM_ENABLE_TESTS)
- # in subdirectory tests:
- set(TESTS_SRCS tests/tests.cpp tests/tests.h)
- add_executable(jom-test ${TESTS_SRCS} ${JOM_SRCS})
- target_link_libraries(jom-test Qt5::Core Qt5::Test)
-
- # copy the data directory 'makefiles' over into the build directory as the tests should be run from there
- file(GLOB_RECURSE JOM_TEST_DATA RELATIVE ${CMAKE_SOURCE_DIR}/tests/makefiles/ "tests/makefiles/*")
- file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/makefiles)
- foreach(_file ${JOM_TEST_DATA})
- configure_file(${CMAKE_SOURCE_DIR}/tests/makefiles/${_file} ${CMAKE_BINARY_DIR}/makefiles/${_file} COPY_ONLY)
- endforeach(_file ${JOM_TEST_DATA})
-
- # add one unit test per function:
- # you can run the unittests all at once using 'make test' from the build directory
- # to produce the list: jom-test --functions | sed 's|[(][)]||'
- set(TEST_NAMES
- includeFiles
- includeCycle
- macros
- invalidMacros
- preprocessorExpressions
- preprocessorDivideByZero
- preprocessorInvalidExpressions
- conditionals
- dotDirectives
- descriptionBlocks
- inferenceRules
- cycleInTargets
- dependentsWithSpace
- multipleTargets
- comments
- fileNameMacros
- fileNameMacrosInDependents
- windowsPathsInTargetName
- caseInsensitiveDependents
- environmentVariables
- ignoreExitCodes
- inlineFiles
- unicodeFiles
- builtin_cd
- suffixes
- nonexistentDependent
- outOfDateCheck
- )
- foreach(TEST_NAME ${TEST_NAMES})
- add_test(${TEST_NAME} jom-test ${TEST_NAME})
- endforeach()
-endif(JOM_ENABLE_TESTS)
diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt
new file mode 100644
index 0000000..417c0e8
--- /dev/null
+++ b/src/app/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_executable(jom
+ application.cpp
+ application.h
+ main.cpp
+ )
+
+set_target_properties(jom PROPERTIES DEBUG_POSTFIX d)
+target_link_libraries(jom PRIVATE jomlib)
+
+install(TARGETS jom RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
diff --git a/src/jomlib/CMakeLists.txt b/src/jomlib/CMakeLists.txt
new file mode 100644
index 0000000..e1adcd4
--- /dev/null
+++ b/src/jomlib/CMakeLists.txt
@@ -0,0 +1,58 @@
+add_library(jomlib STATIC
+ commandexecutor.cpp
+ commandexecutor.h
+ dependencygraph.cpp
+ dependencygraph.h
+ exception.cpp
+ exception.h
+ fastfileinfo.cpp
+ fastfileinfo.h
+ filetime.cpp
+ filetime.h
+ helperfunctions.cpp
+ helperfunctions.h
+ iocompletionport.cpp
+ iocompletionport.h
+ jobclient.cpp
+ jobclient.h
+ jobclientacquirehelper.cpp
+ jobclientacquirehelper.h
+ jobserver.cpp
+ jomprocess.cpp
+ jomprocess.h
+ macrotable.cpp
+ macrotable.h
+ makefile.cpp
+ makefile.h
+ makefilefactory.cpp
+ makefilefactory.h
+ makefilelinereader.cpp
+ makefilelinereader.h
+ options.cpp
+ options.h
+ parser.cpp
+ parser.h
+ ppexpr_grammar.cpp
+ ppexpr_grammar_p.h
+ ppexprparser.cpp
+ ppexprparser.h
+ preprocessor.cpp
+ preprocessor.h
+ stable.h
+ targetexecutor.cpp
+ targetexecutor.h
+ )
+
+target_include_directories(jomlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(jomlib PUBLIC Qt5::Core)
+target_compile_definitions(jomlib PRIVATE
+ QT_NO_CAST_FROM_ASCII
+ QT_NO_CAST_TO_ASCII
+ UNICODE
+ )
+
+if(MSVC)
+ target_compile_definitions(jomlib PUBLIC
+ _CRT_SECURE_NO_WARNINGS
+ )
+endif()
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..7e443cc
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,11 @@
+find_package(Qt5 5.2.0 REQUIRED COMPONENTS Test)
+add_executable(jom-test
+ tests.cpp tests.h)
+
+target_link_libraries(jom-test PRIVATE jomlib Qt5::Test)
+
+add_test(NAME jom-test COMMAND jom-test)
+
+add_custom_command(TARGET jom-test POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/makefiles $<TARGET_FILE_DIR:jom-test>/makefiles
+)