diff options
author | Zachary Lund <admin@computerquip.com> | 2020-02-14 19:27:59 -0600 |
---|---|---|
committer | Zachary Lund <admin@computerquip.com> | 2020-02-15 01:20:50 -0600 |
commit | 08984077ea5f2933b3f25a678a1f2be717ae12d0 (patch) | |
tree | 4fce7c0d17be496fd08a27a37974d51363f826b9 | |
parent | 5f9ebc98618fc1216cde976a2bcf686af119f3ed (diff) | |
download | colm-08984077ea5f2933b3f25a678a1f2be717ae12d0.tar.gz |
add flag to support standalone executables
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | colm/CMakeLists.txt | 8 | ||||
-rw-r--r-- | ragel/CMakeLists.txt | 17 |
3 files changed, 32 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cb910b74..56400bd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,16 @@ set(${PROJECT_NAME}_MAKE_INSTALL ON CACHE BOOL set(${PROJECT_NAME}_BUILD_EXAMPLES OFF CACHE BOOL "Set to ON to build examples (default is OFF)") +# Determine stdlib link flags +if (WIN32) + set(DEFAULT_BUILD_STANDALONE ON) +else() + set(DEFAULT_BUILD_STANDALONE OFF) +endif() + +set(BUILD_STANDALONE ${DEFAULT_BUILD_STANDALONE} + CACHE BOOL "Set to ON to make the executables as standalone as possible.") + # Check type size include(CheckTypeSize) check_type_size("int" SIZEOF_INT) diff --git a/colm/CMakeLists.txt b/colm/CMakeLists.txt index fb84401d..3d855523 100644 --- a/colm/CMakeLists.txt +++ b/colm/CMakeLists.txt @@ -143,6 +143,14 @@ add_executable(colm "${CMAKE_CURRENT_BINARY_DIR}/gen/parse3.c" "${CMAKE_CURRENT_BINARY_DIR}/gen/if3.cc") +if(BUILD_STANDALONE) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_link_libraries(colm -static) + else() + message(FATAL_ERROR "Unsupported toolset for standalone build.") + endif() +endif() + target_link_libraries(colm libprog libcolm) set_property(TARGET colm APPEND PROPERTY diff --git a/ragel/CMakeLists.txt b/ragel/CMakeLists.txt index 448141fe..3e797981 100644 --- a/ragel/CMakeLists.txt +++ b/ragel/CMakeLists.txt @@ -27,7 +27,6 @@ set(RUNTIME_HDR include(GNUInstallDirs) # libfsm - add_library(libfsm buffer.h codegen.h actloop.h actexp.h @@ -59,13 +58,25 @@ set_target_properties(libfsm PROPERTIES OUTPUT_NAME fsm) # libragel - add_library(libragel # dist parsedata.h parsetree.h inputdata.h pcheck.h reducer.h rlscan.h load.h parsetree.cc longest.cc parsedata.cc inputdata.cc load.cc reducer.cc) -target_link_libraries(libragel colm::libcolm) +if(BUILD_STANDALONE) + # libragel acts as an intermediate library so we can apply + # flags we want to apply to all ragel targets to libragel + # and they'll automatically propogate. This is a best effort + # to get `-static` placed sooner in the link line where it + # matters at least. + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_link_libraries(libragel PUBLIC -static) + else() + message(FATAL_ERROR "Unsupported toolset for standalone build.") + endif() +endif() + +target_link_libraries(libragel PRIVATE colm::libcolm) target_include_directories(libragel PUBLIC |